Issue to restore the schema

Peter_1985 2,731 Reputation points
2025-04-25T03:14:41.97+00:00

Dear all,

How to resolve it below?

Exclusive access could not be obtained because the database is in use.

I ran the following    

USE db_to_restore      

go      

ALTER DATABASE db_to_restore SET SINGLE_USER WITH ROLLBACK IMMEDIATE      

go  

but it did not help.

SQL Server Database Engine
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Olaf Helper 46,631 Reputation points
    2025-04-25T09:13:05.18+00:00

    USE db_to_restore  

    Add that's already the cause, you self be connected to the database and so it is in use.

    Use

    USE master

    to be connected to the system database, not to the user DB.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.