SQL-Server: Error - Exclusive access could not be obtained because the database is in use
- Set the path to restore the file.
- Click "Options" on the left hand side.
- Uncheck "Take tail-log backup before restoring"
- Tick the check box - "Close existing connections to destination database".
- Click OK.
I'll assume that if you're restoring a db, you don't care about any existing transactions on that db. Right? If so, this should work for you:
USE master
GO
ALTER DATABASE AdventureWorksDW
SET SINGLE_USER
--This rolls back all uncommitted transactions in the db.
WITH ROLLBACK IMMEDIATE
GO
RESTORE DATABASE AdventureWorksDW
FROM ...
...
GO
Now, one additional item to be aware. After you set the db into single user mode, someone else may attempt to connect to the db. If they succeed, you won't be able to proceed with your restore. It's a race! My suggestion is to run all three statements at once.