SQL Database Restore issues

 trying to restore a database but it  error  said "the database is in use". So, I took the database offline so that I can restore the database. But it is taking over 1 hour to take offline.  Can I stop the process?    How can I restore the database without taking it offline?

April 19th, 2015 8:34pm

so, you want to overwrite the database with the backup.

two things, to do that. 1.you need to get exculsive access on the database 2. use replace in the restore command

you can use:  the below will rollback any uncommitted, open connections and kill them

ALTER DATABASE <<datbasename>>SET Offline WITH ROLLBACK IMMEDIATE

or - use sp_who2 to see what open connections does your database has.

Select * from sys,dm_exec_requests to see which open sessions are currently running some transactions on the database.

you need to kill those sessions. remember, for sessions that are active and running, kill will cause roll back, which will take some time..

KILL <<sessionID>>

or - try to see if you can deatach the database. there should be an option to drop the connections. which is neccassarily same as KILL. if you want to keep it simple, use this method - deattach-reattach and then restore with replace

or- if possible,  stop and start the sql server instance, this will kill all sessions.

once, all sessionss to the database is done, just use restore database mydatabase from disk ='backupath'  with replace,recovery

use recovery if there is only on file else norecovery on all files and recovery on the last

Free Windows Admin Tool Kit Click here and download it now
April 19th, 2015 8:46pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics