超有用。如何将SQL的MODE在MULTI USER和SINGLE USER之间切换
2013-05-23 22:54
281 查看
从多用户切换单用户简单,麻烦的是从单用户切换到多用户。可能会总是出现提示有用户连接的情况。
我试过很多其它办法,都遇阻。
以下代码,完美解决。快,准,狠。
推荐。
f you try to access the database which is already in the Single-User mode, you need to close all the connections to the database first, otherwise you will get an error message:
Msg 5064, Level 16, State 1, Line 1 Changes to the state or options of database 'DatabaseName' 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.
The following query kills the processes accessing the database:
Then you should be able to bring the database back to Multi-User mode as usual:
我试过很多其它办法,都遇阻。
以下代码,完美解决。快,准,狠。
推荐。
f you try to access the database which is already in the Single-User mode, you need to close all the connections to the database first, otherwise you will get an error message:
Msg 5064, Level 16, State 1, Line 1 Changes to the state or options of database 'DatabaseName' 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.
The following query kills the processes accessing the database:
-- Create the sql to kill the active database connections declare @execSql varchar(1000), @databaseName varchar(100) -- Set the database name for which to kill the connections set @databaseName = 'DatabaseName' set @execSql = '' select @execSql = @execSql + 'kill ' + convert(char(10), spid) + ' ' from master.dbo.sysprocesses where db_name(dbid) = @databaseName and DBID <> 0 and spid <> @@spid exec(@execSql) GO
Then you should be able to bring the database back to Multi-User mode as usual:
ALTERDATABASE'DatabaseName'SET MULTI_USER
相关文章推荐
- 使用SQL*Plus操作数据库,当出现Error Message时,如何在简体中文和英文之间切换?
- Set SQL Database User mode to single / multipule(摘)
- 数据库连接不上, 怀疑是不是数据库设置为了single user mode, 如何进行确定?
- 谈谈如何从本质上理解sql语句, 存储过程,ORM之间的联系和取舍。
- 如何做到在虚拟数据库和真实数据库之间自由切换?【低调赠送:QQ高仿版GG 4.4 最新源码】
- (转载)如何在 32 位和 64 内核之间切换?
- VirtualBox single usermode boot
- PADS中如何设置将铺的铜和网络的连接方式进行十字形四根线连接和全部连接之间切换?
- silverlight中如何方便在多个"场景"即Xaml文件之间随意切换?(转)
- Ubuntu如何从user用户切换到root用户
- 在 64 位版本的 Windows 上,如何在 32 位版本的 ASP.NET 1.1 和 64 位版本的 ASP.NET 2.0 之间切换
- 如何控制静态Form类与普通的Form类之间的切换
- ARM处理器各个模式之间是如何切换的?ARM各个模式之间切换时,上下文的保存哪些是硬件在做?哪些是操作系统在做?
- silverlight中如何方便在多个"场景"即Xaml文件之间随意切换?
- 在64位版本的Windows上,如何在32位版本的ASP.NET 1.1 和64位版本的ASP.NET 2.0之间切换
- 如何自己写一个容器来实现viewController之间的切换
- redhat enter single user mode after execute ‘shutdow now’ command
- 页面中Div之间如何进行切换???
- ubuntu如何在多个工作区之间自由切换以及添加返回桌面图标
- 导航视图控制器中如何定义按钮以及视图之间的切换