Issue with restore a bak database file: “Exclusive Access could not be obtained because the database is in use.”


When we try to restore a database from a backup file, we may run into this error message:
 "Exclusive Access could not be obtained because the database is in use." We can fix this error to restore our database by changing the database to single_user mode to disconnect all connections and try to run restore again and finally to reset the database back to multiple user mode to finish up the process.
 
1. USE [master]
ALTER DATABASE [mydb]
SET single_user with rollback immediate;
 

2. Restore your database again.

3.USE [master]
ALTER DATABASE [mydb]
SET multi_user;

Advertisements


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s