This is an article on how to do a restore from backup on a database but when you get the error: "... database is in use".
-- SQL Server 2005
EXEC SP_WHO // details on who is logged in
GO
-- SQL Server 2008
EXEC SP_WHO2 // even more details
GO
-- Run as database owner to see ALL connected processes as well.
Why?
For every DBA this is a doddle and doesn't warrant its own article but for those of us who merely use SQL Server Management Studio (SSMS) and Microsoft's SQL Server 2008 R2 for development purposes, the once-in-a-blue-moon restore from backup process is quickly forgotten.
How?
You need to set the database to single-user mode.
- In SSMS, connect to an instance of the SQL Server Database Engine, and then expand that instance.
- Right-click the database to change, and then click Properties.
- In the Database Properties dialog box, click the Options page.
- From the Restrict Access option, select Single.
- If other users are connected to the database, an Open Connections message will appear. To change the property and close all other connections, click Yes.
- in SSMS, Right-click on the database
- Select Tasks > Restore... > Database
- Specify the "to a point in time" if you don't want to restore from the most recent backup and double-check the "Start/Finish Date" is the one you want.
- OK
Searches
- ssms restore database in use
- Cannot drop database because it is currently in use
- Restoring a SQL Database Backup Using SQL Server Management Studio
- Unable to restore database "..because it is in use by this session."
- determine who is connected to sql database
Sources
Discussion
Comments
Questions, corrections and useful additions are reviewed before appearing here.
No comments yet. Start the discussion.