标题: [转贴] VBScrit脚本结束指定库的所有用户连接 [打印本页]
作者: find 时间: 2012-3-25 14:12 标题: VBScrit脚本结束指定库的所有用户连接
在使用vbs导入数据库时确实会存在数据库正在读写或者正在使用中的报错提示,其实数据库已经进入单用户模式,无人调用,写一个脚本来杀。
- declare @spid int
- declare Spid_cursor cursor for
- select spid from master.dbo.sysprocesses with (nolock) where loginame = '用户名' and blocked <> 0 order by spid
- open Spid_cursor
- fetch next from Spid_cursor into @spid
- while @@FETCH_STATUS = 0
- begin
- --exec('kill '+@spid) //屏蔽后是查询功能
- print 'Killed Spid=' + cast(@spid as nvarchar(200))
- fetch next from Spid_cursor into @spid
- end
- close Spid_cursor
- deallocate Spid_cursor
复制代码
http://bobwu.blog.51cto.com/2918362/531213
欢迎光临 批处理之家 (http://bbs.bathome.net/) |
Powered by Discuz! 7.2 |