ALTER DATABASE 失败,因为无法在数据库上放置锁 [英] ALTER DATABASE failed because a lock could not be placed on database
问题描述
我需要重新启动数据库,因为某些进程不工作.我的计划是将其离线并重新上线.
I need to restart a database because some processes are not working. My plan is to take it offline and back online again.
我正在尝试在 Sql Server Management Studio 2008 中执行此操作:
I am trying to do this in Sql Server Management Studio 2008:
use master;
go
alter database qcvalues
set single_user
with rollback immediate;
alter database qcvalues
set multi_user;
go
我收到这些错误:
Msg 5061, Level 16, State 1, Line 1
ALTER DATABASE failed because a lock could not be placed on database 'qcvalues'. Try again later.
Msg 5069, Level 16, State 1, Line 1
ALTER DATABASE statement failed.
Msg 5061, Level 16, State 1, Line 4
ALTER DATABASE failed because a lock could not be placed on database 'qcvalues'. Try again later.
Msg 5069, Level 16, State 1, Line 4
ALTER DATABASE statement failed.
我做错了什么?
推荐答案
出现错误后,运行
EXEC sp_who2
在列表中查找数据库.连接可能未终止.如果您发现与数据库的任何连接,请运行
Look for the database in the list. It's possible that a connection was not terminated. If you find any connections to the database, run
KILL <SPID>
其中
是连接到数据库的会话的 SPID.
where <SPID>
is the SPID for the sessions that are connected to the database.
在删除与数据库的所有连接后尝试您的脚本.
Try your script after all connections to the database are removed.
很遗憾,我不知道您看到问题的原因,但这里有一个链接,表明问题发生在其他地方.
Unfortunately, I don't have a reason why you're seeing the problem, but here is a link that shows that the problem has occurred elsewhere.
这篇关于ALTER DATABASE 失败,因为无法在数据库上放置锁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!