"Cannot obtain exclusive access to a database because the database is in use" solution __ Database

Source: Internet
Author: User
Description of the problem: after the SQL Server database backup is restored, the word "restricted access" appears after the database name

Problem two description: When restoring to a SQL Server database, prompt: System.Data.SqlClient.SqlError: Cannot obtain exclusive access to a database because the database is in use. (MICROSOFT.SQLSERVER.SMO). This problem occurs because another user is using the database when the database is restored. Restoring a database requires that the database work in Single-user mode. Typically, the DBA does not allow other users to connect to the database while it is operating.

Problem One solution:
Right-click the database-> properties-> option-> status-> restricted access-> Select multiple-> OK.

Problem Two solutions:
Method one (most convenient): Right-click the database-> properties-> option-> status-> restricted access-> select Single-> OK. and then restore.
Method two (most direct): Disconnect the database
Method III (Most violent): Logout/Restart the database server
Method four (most troublesome): Write code to modify the database related properties, although the trouble, sometimes still need to use, then use the time to study. Method V (End-level solution):

Critical SQL statements:

ALTER DATABASE [datebase] SET OFFLINE with ROLLBACK IMMEDIATE

Run out and then

ALTER database [Datebase] set online

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.