问题
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