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

You may come across an error as shown below while backup/restoring a database using SQL Server Management Studio 2005.

Restore failed for ‘servername’ (Microsoft.SqlServer.Smo)
Additional information:
System.Data.SqlClient.SqlError: Exclusive access could not be obtained because the database is in use. (Microsoft.SqlServer.Smo)

[SQLerror.gif]

This is because a process that was using the database has been unexpectedly killed without releasing the resources or other users or session is using the database at the same time

There are couple of workarounds:

A) Restart SQL Server service

  1. Start -> Run and type in services.msc
  2. Right click SQL Server (MSSQLSERVER) Stop and then Start the service
  3. You should be fine to restore your database

B) Find the process and kill it

To see other users using the database use:
Execute SP_WHO

To kill the process (be a killer!!!) execute
Execute KILL 53
where 53 is the process id spid=53 (found in the result list provided by Execute SP_WHO)

You should be all right with restoring database now. If the issue persist then Option (A) would be a way to go.

Advertisements
This entry was posted in SQL Server. Bookmark the permalink.

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

  1. HB says:

    Thnks.. It worked 🙂

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