Unable to gain exclusive access to the database because the database is in use---Resolution to restore or delete the database

Source: Internet
Author: User

Problem description: After a 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, Tip: System.Data.SqlClient.SqlError: Because the database is in use, you cannot gain exclusive access to the database. (MICROSOFT.SQLSERVER.SMO). This problem occurs because another user is using the database while the database is being restored. Restoring a database requires the database to 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 Database--Properties-----restricted access, state---Select multiple-OK.

Problem Two solutions:

Method one (most convenient): Right-click the database--Properties----state-----Select single-> OK. and then restore.

Method two (most direct): Disconnecting database connections

Method three (most violent): Log off/Restart the database server

Method Four (the most troublesome): Write code to modify the database related properties, although the trouble, sometimes still need to use, then use the time to study.

When you restore or delete a SQL Server 2008 database, the frequently-stewed occurrences are:

"Because the database is in use, you cannot gain exclusive access to the database", the Final solution is as follows


Key SQL statements:

ALTER DATABASE [datebase] SET OFFLINE with ROLLBACK IMMEDIATE


Run out and then


ALTER database [Datebase] set online

Unable to gain exclusive access to the database because the database is in use---Resolution to restore or delete the database

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.