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)
System.Data.SqlClient.SqlError: Exclusive access could not be obtained because the database is in use. (Microsoft.SqlServer.Smo)
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
- Start -> Run and type in services.msc
- Right click SQL Server (MSSQLSERVER) Stop and then Start the service
- You should be fine to restore your database
B) Find the process and kill it
To see other users using the database use:
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.