Skip to content

Tag «kill connection»

How to kill all connections to a SQL Server DB

Script to accomplish this, replace ‘DB_NAME’ with the database to kill all connections to: USE master GO SET NOCOUNT ON DECLARE @DBName varchar(50) DECLARE @spidstr varchar(8000) DECLARE @ConnKilled smallint SET @ConnKilled=0 SET @spidstr = ” Set @DBName = ‘DB_NAME’ IF db_id(@DBName) < 4 BEGIN PRINT ‘Connections to system databases cannot be killed’ RETURN END SELECT …