Drop all connections to a sql 2005 database


/ Published in: SQL
Save to your folder(s)



Copy this code and paste it in your HTML
  1. USE master
  2. GO
  3.  
  4. DECLARE @dbname sysname
  5.  
  6. SET @dbname = 'name of database you want to drop connections from'
  7.  
  8. DECLARE @spid INT
  9. SELECT @spid = MIN(spid) FROM master.dbo.sysprocesses WHERE dbid = db_id(@dbname)
  10. WHILE @spid IS NOT NULL
  11. BEGIN
  12. EXECUTE ('KILL ' + @spid)
  13. SELECT @spid = MIN(spid) FROM master.dbo.sysprocesses WHERE dbid = db_id(@dbname) AND spid > @spid
  14. END

URL: http://www.julian-kuiters.id.au/article.php/sql-server-2005-snippet-drop-db-conn

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.