首页 > 数据库技术 > 详细

无法将数据库从SINGLE_USER模式切换回MULTI_USER模式(Error 5064)

时间:2018-11-29 14:14:51      阅读:260      评论:0      收藏:0      [点我收藏+]

今天公司SQL Server数据库无意间变为SINGLE_USER模式了,而且使用如下语句切换回MULTI_USER失败:

ALTER DATABASE [MyDB] SET MULTI_USER  WITH ROLLBACK IMMEDIATE 

报错:

Msg 5064, Level 16, State 1, Line 1
Changes to the state or options of database ‘MyDB‘ cannot be made at this time. The database is in single-user mode, and a user is currently connected to it.
Msg 5069, Level 16, State 1, Line 1
ALTER DATABASE statement failed.

该错误提示是有其它用户在使用数据库,没办法只好排查是谁:

 

1)通过sys.sysprocesses或者sys.dm_exec_sessions,或者存储过程sp_who,然后用KILL命令把会话切断

select * from sys.sysprocesses 
where spid > 50
And dbid=DB_ID (MyDB)

 

SELECT * FROM sys.dm_exec_sessions
WHERE database_id = DB_ID (MyDB)

 

2)如果上面还是行不通,再检查sys.dm_tran_locks,然后用KILL命令把会话切断

select * from sys.dm_tran_locks where resource_database_id= DB_ID (MyDB)

 

 

技术分享图片

kill 148

 

无法将数据库从SINGLE_USER模式切换回MULTI_USER模式(Error 5064)

原文:https://www.cnblogs.com/OpenCoder/p/10037560.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!