终止数据库连接进程SQL
2015-07-03 23:09
309 查看
数据库连接被占用时,使用下面SQL可以强制关闭连接:
declare @spid int;
declare @ddlstring nvarchar(max);
declare @dbname varchar(200);
set @dbname='dbname'
declare tmpcur cursor
for select distinct spid as spid from sys.sysprocesses where dbid=DB_ID(@dbname);
open tmpcur;
fetch tmpcur into @spid;
while(@@FETCH_STAUS=0)
begin
set @ddlstring=N'KILL '+CONVERT(NVARCHAR,@spid);
execute sp_executesql @ddlstring;
fetch tmpcur into @spid;
end;
close tmpcur;
deallocate tmpcur;
declare @spid int;
declare @ddlstring nvarchar(max);
declare @dbname varchar(200);
set @dbname='dbname'
declare tmpcur cursor
for select distinct spid as spid from sys.sysprocesses where dbid=DB_ID(@dbname);
open tmpcur;
fetch tmpcur into @spid;
while(@@FETCH_STAUS=0)
begin
set @ddlstring=N'KILL '+CONVERT(NVARCHAR,@spid);
execute sp_executesql @ddlstring;
fetch tmpcur into @spid;
end;
close tmpcur;
deallocate tmpcur;
相关文章推荐
- centos 6.3 & redis install
- Redis本地环境搭建
- Redis配置文件详解
- Redis基本操作-20150608
- Redis操作命令
- 高性能的分布式内存对象缓存系统Memcached
- mysql 5.6 时间函数的变化 FROM_UNIXTIME CURRENT_TIMESTAMP
- 支付宝高级技术专家杨传辉:OceanBase 0.4 从API到SQL
- IQ存储过程中执行有结果集返回的动态SQL的调用方法
- 豌豆夹Redis解决方案Codis源码剖析:Proxy代理
- 豆瓣Redis解决方案Codis源码剖析:Proxy代理
- PostgreSQL中select into用法总结
- PostgreSQL游标使用举例
- Hibernate连接oracle数据库的简单例子
- mysql事务
- postgreSQL数据类型
- (十)HTML5本地存储——SQLLite实现web留言本
- 缓存框架——Redis(一)
- 缓存框架——Redis(一)
- (九)HTML5本地存储——本地数据库SQLLite的使用