无法获得独占访问权限,因为数据库正在使用 - 但数据库已被删除 [英] Exclusive access could not be obtained because the database is in use - but the database is deleted
问题描述
即使删除了数据库,也有人遇到过这个错误吗?我删除了数据库并在删除之前检查了关闭现有连接"框.
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.
我有一个实时数据库和一个测试数据库.我已经备份了 Live.当我尝试将 Live.bak 恢复到名为 Test 的数据库时,出现独占访问错误.我需要通过测试复制实时数据库.
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.
推荐答案
在删除之前关闭现有连接总是更好
It is always better to close existing connections before deleting
ALTER DATABASE MyDB
SET SINGLE_USER
WITH ROLLBACK IMMEDIATE;
使用相同的名称重新附加它并重命名数据库.或使用 norecovery
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'
-- 移动文件位置
WITH MOVE 'MDFLogicalName' TO 'C:\test.mdf',
MOVE 'LDFLogicalname' TO 'D:\Test.ldf'
这篇关于无法获得独占访问权限,因为数据库正在使用 - 但数据库已被删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!