For a list of open connections for a specific database you can run the following command:
select spid from master..sysprocesses where dbid = db_id('Works') and spid <> @@spid
Kill all open connections to a specific database:
DECLARE @DatabaseName nvarchar(50)
DECLARE @SPId int
SET @DatabaseName = N'Works'
DECLARE my_cursor CURSOR FAST_FORWARD FOR
SELECT SPId FROM MASTER..SysProcesses WHERE DBId = DB_ID(@DatabaseName) AND SPId <> @@SPId
OPEN my_cursor
FETCH NEXT FROM my_cursor INTO @SPId
WHILE @@FETCH_STATUS = 0
BEGIN
KILL @SPId
FETCH NEXT FROM my_cursor INTO @SPId
END
CLOSE my_cursor
DEALLOCATE my_cursor
Comments
Post a Comment