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