Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2247566
  • 博文数量: 310
  • 博客积分: 6853
  • 博客等级: 准将
  • 技术积分: 2833
  • 用 户 组: 普通用户
  • 注册时间: 2005-08-04 16:41
文章分类

全部博文(310)

文章存档

2013年(17)

2012年(42)

2011年(76)

2010年(71)

2009年(99)

2007年(2)

2006年(1)

2005年(2)

分类: 数据库开发技术

2010-11-22 16:38:29

防止管理员做这种操作,因为这样反而会破坏连接池的作用。


存储过程完成对无用或闲置时间过长的SQL连接回收代码如下:



use master
go
create proc KillSpByDbName(@dbname varchar(20))
as
begin
declare @temp varchar(1000)
declare @spid int
declare getspid cursor for
    select spid from sysprocesses a where dbid=db_id(@dbname) and status='sleeping' and (select datediff(n,last_batch,getdate()) from sysprocesses b where b.spid=a.spid)>10
open getspid
fetch next from getspid into @spid
while @@fetch_status <>-1
begin
set @temp='kill '+rtrim(@spid)
exec(@temp)
fetch next from getspid into @spid
end
close getspid
deallocate getspid
end


阅读(5336) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~