Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Kill all connection to database


Kill all connection to database

Author
Message
skra
skra
Say Hey Kid
Say Hey Kid (712 reputation)Say Hey Kid (712 reputation)Say Hey Kid (712 reputation)Say Hey Kid (712 reputation)Say Hey Kid (712 reputation)Say Hey Kid (712 reputation)Say Hey Kid (712 reputation)Say Hey Kid (712 reputation)

Group: General Forum Members
Points: 712 Visits: 228
Comments posted to this topic are about the item Kill all connection to database
dant12
dant12
SSC Veteran
SSC Veteran (254 reputation)SSC Veteran (254 reputation)SSC Veteran (254 reputation)SSC Veteran (254 reputation)SSC Veteran (254 reputation)SSC Veteran (254 reputation)SSC Veteran (254 reputation)SSC Veteran (254 reputation)

Group: General Forum Members
Points: 254 Visits: 711
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
skra
skra
Say Hey Kid
Say Hey Kid (712 reputation)Say Hey Kid (712 reputation)Say Hey Kid (712 reputation)Say Hey Kid (712 reputation)Say Hey Kid (712 reputation)Say Hey Kid (712 reputation)Say Hey Kid (712 reputation)Say Hey Kid (712 reputation)

Group: General Forum Members
Points: 712 Visits: 228
You're right - this procedure would be much more simple if I used cursors as You did.
rktn_odin
rktn_odin
Grasshopper
Grasshopper (20 reputation)Grasshopper (20 reputation)Grasshopper (20 reputation)Grasshopper (20 reputation)Grasshopper (20 reputation)Grasshopper (20 reputation)Grasshopper (20 reputation)Grasshopper (20 reputation)

Group: General Forum Members
Points: 20 Visits: 163
i use this:


ALTER DATABASE Northwind SET SINGLE_USER WITH ROLLBACK IMMEDIATE
EXEC sp_dboption 'Northwind', 'single user', 'FALSE'


Oliver Wootton
Oliver Wootton
Grasshopper
Grasshopper (23 reputation)Grasshopper (23 reputation)Grasshopper (23 reputation)Grasshopper (23 reputation)Grasshopper (23 reputation)Grasshopper (23 reputation)Grasshopper (23 reputation)Grasshopper (23 reputation)

Group: General Forum Members
Points: 23 Visits: 536
--Kill all users instantly

use master
go
alter database test set offline with rollback immediate
go
alter database test set online
go
Iwas Bornready
Iwas Bornready
SSCrazy Eights
SSCrazy Eights (8.7K reputation)SSCrazy Eights (8.7K reputation)SSCrazy Eights (8.7K reputation)SSCrazy Eights (8.7K reputation)SSCrazy Eights (8.7K reputation)SSCrazy Eights (8.7K reputation)SSCrazy Eights (8.7K reputation)SSCrazy Eights (8.7K reputation)

Group: General Forum Members
Points: 8706 Visits: 885
Thanks for the script.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search