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

懵懂的女人 提交于 2019-12-24 20:03:20

问题


Has anyone run into this error even when the database is deleted? I deleted the database and checked the "close existing connections" box before deleting.

I have a Live db and a Test Db. I have made a backup of Live. When I try to restore Live.bak to a database with name Test, I get the exclusive access error. I need to copy the Live db over Test.

Funny thing is I can restore a backup of Test if needed.


回答1:


It is always better to close existing connections before deleting

ALTER DATABASE MyDB
SET SINGLE_USER
WITH ROLLBACK IMMEDIATE;

Reattach it with same name and rename the database. Or restore with norecovery

RESTORE DATABASE TEST FROM DISK = 'C:\Live.BAK' WITH NORECOVERY
RESTORE LOG TEST FROM DISK = 'C:\LIVELOG.trn'

-- Moving file lcoations

WITH MOVE 'MDFLogicalName' TO 'C:\test.mdf',
MOVE 'LDFLogicalname' TO 'D:\Test.ldf'


来源:https://stackoverflow.com/questions/49015797/exclusive-access-could-not-be-obtained-because-the-database-is-in-use-but-the

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!