February 28, 2011 at 8:37 pm
Comments posted to this topic are about the item Kill all connection to database
March 1, 2011 at 7:10 am
i often use something more simple
DECLARE @TARGET INT
WHILE 1=1
BEGIN
DECLARE KILLCONS CURSOR LOCAL FAST_FORWARD FOR
SELECT SPID FROM MASTER..SYSPROCESSES WHERE DBID = DB_ID('DB NAME') AND SPID >=50
OPEN KILLCONS
FETCH NEXT FROM KILLCONS INTO @TARGET
WHILE @@FETCH_STATUS = 0
BEGIN
EXEC ('KILL '+@TARGET)
FETCH NEXT FROM KILLCONS INTO @TARGET
END
CLOSE KILLCONS
DEALLOCATE KILLCONS
END
the infinite while is to take care of pesky applications that keep reconnecting, so you just manually break the loop when you feel like it
--
Thiago Dantas
@DantHimself
March 1, 2011 at 7:37 am
You're right - this procedure would be much more simple if I used cursors as You did.
March 8, 2011 at 12:49 am
i use this:
ALTER DATABASE Northwind SET SINGLE_USER WITH ROLLBACK IMMEDIATE
EXEC sp_dboption 'Northwind', 'single user', 'FALSE'
May 19, 2011 at 6:54 am
--Kill all users instantly
use master
go
alter database test set offline with rollback immediate
go
alter database test set online
go
May 17, 2016 at 6:33 am
Thanks for the script.
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply