博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
超有用。如何将SQL的MODE在MULTI USER和SINGLE USER之间切换
阅读量:7029 次
发布时间:2019-06-28

本文共 1151 字,大约阅读时间需要 3 分钟。

从多用户切换单用户简单,麻烦的是从单用户切换到多用户。可能会总是出现提示有用户连接的情况。

我试过很多其它办法,都遇阻。

以下代码,完美解决。快,准,狠。

推荐。

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

转载地址:http://bcwal.baihongyu.com/

你可能感兴趣的文章
typeof和instanceof的区别
查看>>
XAMPP Windows 安装中报错解决方法备忘
查看>>
sublime之利器使用篇
查看>>
每个类都应将所有能力以最小粒度提供给外部可配置,每个业务所需要的功能是这些能力的组合...
查看>>
使用cached的wrapper类读取请求响应内容
查看>>
[python][os]分离文件目录,文件名以及文件后缀
查看>>
解决Android Studio SDK无法下载问题
查看>>
雷军定AI+IoT为小米核心战略,牵手宜家推进生态布局
查看>>
书评:《All About Java 8 Lambdas》
查看>>
搜狗信息流推荐算法实践
查看>>
Visual Studio 2017 15.6发布
查看>>
2019年Java和JVM生态系统预测:OpenJDK将成为Java运行时市场领导者
查看>>
拥抱PostgreSQL,红帽再表态:SSPL的MongoDB坚决不用
查看>>
架构设计复杂度的6个来源
查看>>
360首席安全官谭晓生宣布离职
查看>>
在敏捷中应用测试驱动开发
查看>>
到底谁应该对软件开发的质量负责?
查看>>
微软Windows Core OS被曝应用了开源组件
查看>>
用Elm语言降低失败的风险
查看>>
资深专家都知道的Docker常用命令
查看>>