强制断开sql server数据库已有连接的方法 -宏鹏
Access软件网QQ交流学习群(群号码198465573),欢迎您的加入!
首页 >技术文章> ADP及SQL SERVER


强制断开sql server数据库已有连接的方法

发表时间:2018/8/22 8:13:21 评论(0) 浏览(5416)  评论 | 加入收藏 | 复制
   
摘 要:强制断开sql server数据库已有连接的方法 
正 文:
declare @i int declare cur cursor for select spid from sysprocesses where db_name(dbid)= 'Your_Database_Name' open cur fetch next from cur into @i while @@fetch_status=0 begin exec('kill '+@i) fetch next from cur into @i end close cur deallocate cur

为了方便,可以把这条sql写到建库的批处理脚本里,放在脚本的开始

:: Disconnect existing Fortune database connectionsosql -S"%1" -U"%2" -P"%3" -Q"declare @i int declare cur cursor for select spid from sysprocesses where db_name(dbid)= ' Your_Database_Name ' open cur fetch next from cur into @i while @@fetch_status=0 begin exec('kill '+@i) fetch next from cur into @i end close cur deallocate cur"


另外,分离数据库时,选择切断所有的连接,也是一种办法。


Access软件网交流QQ群(群号:198465573)
 
 相关文章
快速断开sql连接  【缪炜  2016/6/17】
查看sql server 2005连接数  【缪炜  2017/11/10】
判断是否可以连接SQL Server数据库  【大海  2017/11/30】
平台企业版如何连接后台sql中其他数据库  【MDZZ  2018/1/22】
DSN-less连接策略  【萤火虫  2018/6/10】
常见问答
技术分类
相关资源
文章搜索
关于作者

宏鹏

文章分类

文章存档

友情链接