Home
Manage Your Code
Snippet: kill active connections to database (SQL)
Title: kill active connections to database Language: SQL
Description: kills all the active connections to a database Views: 131
Author: Yordan Georgiev Date Added: 5/25/2009
Copy Code  
print 'Killing active connections to the "' + 'OCMS_DEV' + '" database'
declare @execSql varchar(400)
-- Create the sql to kill the active database connections
set @execSql = ''
select @execSql = @execSql + 'kill ' + convert(char(10), spid) + ' '
from master.dbo.sysprocesses
where db_name(dbid) = 'OCMS_DEV'
and
DBID <> 0
and
spid <> @@spid
exec (@execSql)