SQL Server Error During Restore Database: “Exclusive access could not be obtained because the database is in use”

Mert Ilis
1 min readNov 19, 2014

--

Today I needed to restore a database to our test environment but the I got the following error during the restore operation:

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

The reason of this SQL error is there are other users currently using the database to be restored. When trying to do a restore, if any other user is in the database you will see this error.

Therefore you should first drop any other connections in this database. sp_who2 procedure can be used to see what connections are using the database you are trying to restore.

To drop connection run these two commands:

alter database your_db_name set offline with rollback immediatealter database your_db_name set online

After this; you can restore your database as usual…

Originally published at http://www.weboideas.com on November 19, 2014.

--

--

Mert Ilis

I’m a software development enthusiast who likes trying different web technologies and adding value to his team.