Friday, March 1, 2013

exclusive access could not be obtained as database is in use when restoring the databse

I was trying to restore the database from production to our development environment today and got the error

exclusive access could not be obtained as database is in use  while restoring the database , this error occurs when some users or some job or some other process is using the database ..
so to restore the database  successfully please follow the steps


USE [master]
GO

ALTER DATABASE mydb SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
GO

Then RESTORE the DATABASE


IF YOU STILL GET THE ERROR
exclusive access could not be obtained as database is in use , EVEN IF THE DATABASE IS IN SINGLE
USER MODE

CHECK SP_WHO2, sys processes and


CLOSE the connections , CLOSE SSMS AND

OPEN again SSMS 
then RESTORE the DATABASE it will be Restored successfully this time





Thanks





No comments:

Post a Comment

https://blog.sqlauthority.com/2009/06/27/sql-server-fix-error-17892-logon-failed-for-login-due-to-trigger-execution-changed-database-context...