Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 Script Library
 Kill multiple user connections
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Most Valuable Yak

15732 Posts

Posted - 09/17/2004 :  08:18:09  Show Profile  Visit robvolk's Homepage  Reply with Quote
CREATE procedure sp_murder @name varchar(128)=null, @doit bit=0 AS
set nocount on
declare @sql varchar(8000)
set @sql=''
select @sql=@sql + 'KILL ' + cast(spid as varchar) + '; ' +char(13) + char(10) from sysprocesses
where loginame LIKE '%' + @name + '%' or db_name(dbid) LIKE '%' + @name + '%' 
select @sql=@sql + 'KILL ' + cast(spid as varchar) + '; ' +char(13) + char(10) from sysprocesses
where (status='sleeping' and spid>8 AND dbid>1 AND nt_username<>'SYSTEM' and login_time<getdate()-1 and last_batch<getdate()-.25)

if @doit=0 select @sql ELSE exec(@sql)


exec sp_murder --lists spids that are killable cause they're old
exec sp_murder null, 1 --actually kill the spids returned from above
exec sp_murder 'myDB', 1 --kill users in myDB
exec sp_murder 'username', 1 --kill all connections made by user "username"
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.02 seconds. Powered By: Snitz Forums 2000