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

Frank Martin 411 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.
8,541 questions
No comments
{count} votes

Accepted answer
  1. Erland Sommarskog 67,821 Reputation points Microsoft 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!
    
    No comments

0 additional answers

Sort by: Most helpful