Workaround for SQL Server to prompt database when restoring database is in use and cannot be manipulated

Source: Internet
Author: User

When SQL Server restores the database, it prompts, "because the database is in use, you cannot obtain exclusive access to the database", whether I restart the database, or restart the computer, the separation of the database, will not solve the problem, after many attempts, and find the data, finally resolved the problem.

First, use the SQL statement to kill all the process code that is using the database as follows

  

The SQL statement uses the cursor to loop through all the processes that are using the database and kills the process with the kill command.

Second, the use of SQL statements, disconnect all user links, and rollback all transactions, the specific SQL statement is as follows

ALTER database [DB name] SET OFFLINE with ROLLBACK IMMEDIATE

Attention:

1.SQL statements to be executed under the master database

2. To see if cleaning is clear, use the following SQL statement

  

Workaround for SQL Server to prompt database when restoring database is in use and cannot be manipulated

Related Article

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.