SQL Server - Exclusive access could not be obtained because the database is in use

Frank Martin 456 Reputation points
2022-12-25T09:40:50.333+00:00

Took backup of database from SQL Server 2008 R2 Enterprise and trying to restore it on a database on SQL Server 2019 Enterprise but getting error:

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

I took destination database offline and then tried to restore but no luck. Restarted SQL Server service but no luck. Close existing connections to destination database is checked under Options but no luck (screenshot attached). There is enough disk space available.

Is the error coming due to version difference? If yes, then how to restore database from 2008 R2 to 2019?
EnfnA.png

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
13,789 questions
0 comments No comments
{count} vote

Accepted answer
  1. Erland Sommarskog 111.1K Reputation points MVP
    2022-12-25T11:09:25.623+00:00

    No, this has nothing to do with the version difference. The issue is exactly what the error message says: there are one or more processes active in this database. Well, active and active... If you have a query window open with this database as the current database that counts. Or you could have a node open in the database in Object Explorer. SQL Server don't want to make the decision to pull the rug for these processes itself, but if you know that it is OK, you can do this;

    First, use the Script button on the top of the dialogue to script the RESTORE statement to a new query window. Then above the RESTORE command, add:

       USE db_to_restore  
       go  
       ALTER DATABASE db_to_restore SET SINGLE_USER WITH ROLLBACK IMMEDIATE  
       go  
       USE tempdb  
       go  
       ``  
       And please bear in mind that the current database will be entirely overwritten, so be careful!
    
    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

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.