The solution for "Restore failed for Server: Exclusive access could not be obtained because the database is in use." is closing all existing connection to the destination database by setting the database to a SINGLE_USER
How to restore the database is in use?
- Open SQL Server Management Studio.
- Right-click on
databases
> select "Restore Database".
- In
general
, select the source of your backup.
- In options, check "Close existing connections to destination database".
Alternatively, You can also restore your database using the below SQL query:
ALTER DATABASE DB_NAME SET SINGLE_USER WITH ROLLBACK IMMEDIATE
GO
RESTORE DATABASE DB_NAMEFROM DISK = 'C:\Backuppath.BAK'
GO
Note: whatever the way that you will use to restore the database in use, after performing the restore, you should make sure that the database is not set to SINGLE_USER.
If your database still in a SINGLE_USER state, you should set it to MULTI_USER by running the below query
ALTER DATABASE DB_NAME
SET MULTI_USER
GO
See Also