Thursday, November 17, 2005
How to disconnect SQL Server 2000 logins
The following code snippet will search for connections by the user 'fred' and will kill them by SPID.
declare @spid varchar(10)
declare spids cursor for
select convert(varchar, spid) from master.dbo.sysprocesses
where ecid = 0 and loginame='fred'
open spids
while(1=1)
begin
fetch spids into @spid
if @@fetch_status 0 break
print 'Killing spid ' + @spid
exec('kill ' + @spid)
end
deallocate spids

