Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Kill SPIDs through automated job(while restore) Expand / Collapse
Author
Message
Posted Thursday, July 17, 2008 11:27 AM


SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Tuesday, November 22, 2016 1:45 PM
Points: 213, Visits: 502
Comments posted to this topic are about the item Kill SPIDs through automated job(while restore)
Post #536183
Posted Friday, December 2, 2016 7:54 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: 2 days ago @ 12:54 PM
Points: 263, Visits: 1,043
This is our attempt at it:

declare @SPId varchar(1000)
Print '[SQLTRIX] Killing active connections'
Print ''
SELECT @SPId = COALESCE(@SPId,'')+'KILL '+CAST(SPID AS VARCHAR)+'; '
FROM Master..SysProcesses WHERE DB_NAME(DBId) = '?DB_NAME?'--@DBNAME
and spid >= 50 and SPId <> @@spid
PRINT @SPId
EXEC(@SPId)
Print ''
GO

I find we can't start the restore fast enough about 1/4 of the time.
Post #1839694
Posted Friday, December 2, 2016 8:17 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 1:24 AM
Points: 7,061, Visits: 14,764
Or this:
ALTER DATABASE SQLTRIX SET SINGLE_USER WITH ROLLBACK IMMEDIATE

You can use RESTRICTED USER instead of SINGLE USER if that's more appropriate (in other words if none of the processes that are likely to connect to the database will do so as db_owner or higher).

John
Post #1839704
Posted Friday, December 2, 2016 8:35 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: 2 days ago @ 12:54 PM
Points: 263, Visits: 1,043
John Mitchell-245523 (12/2/2016)
Or this:
ALTER DATABASE SQLTRIX SET SINGLE_USER WITH ROLLBACK IMMEDIATE

You can use RESTRICTED USER instead of SINGLE USER if that's more appropriate (in other words if none of the processes that are likely to connect to the database will do so as db_owner or higher).

John


Do you have any issues of another process getting in there or does the system make the process the SINGLE USER?
Post #1839715
Posted Friday, December 2, 2016 8:40 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 1:24 AM
Points: 7,061, Visits: 14,764
I'm not sure exactly how it works, but I don't think I've ever had a restore fail on database in use after setting it to single user. I suppose it's possible, which is why I said restricted user may be more appropriate in some cases.

John
Post #1839719
Posted Friday, December 2, 2016 9:00 AM
Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Yesterday @ 11:13 AM
Points: 3,853, Visits: 6,571
Personally I've had much lesser delays/stalls using this command:


ALTER DATABASE SQLTRIX SET OFFLINE WITH ROLLBACK_IMMEDIATE;


And you can get into devilish issues with "SINGLE_USER". You need to make sure you are in the db, sometimes the single_user takes SQL a while to "disassociate". Also a real pain if some other task happens to jump in ahead of you in getting to the db and it becomes the single user, and you're totally locked out of the db.


SQL DBA,SQL Server MVP('07, '08, '09)

Prosecutor James Blackburn, in closing argument in the "Fatal Vision" murders trial: "If in the future, you should cry a tear, cry one for them [the murder victims]. If in the future, you should say a prayer, say one for them. And if in the future, you should light a candle, light one for them."
Post #1839732
Posted Friday, December 2, 2016 9:11 AM
SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 1:13 AM
Points: 6,565, Visits: 17,276
ScottPletcher (12/2/2016)
Personally I've had much lesser delays/stalls using this command:


ALTER DATABASE SQLTRIX SET OFFLINE WITH ROLLBACK_IMMEDIATE;


And you can get into devilish issues with "SINGLE_USER". You need to make sure you are in the db, sometimes the single_user takes SQL a while to "disassociate". Also a real pain if some other task happens to jump in ahead of you in getting to the db and it becomes the single user, and you're totally locked out of the db.


+1
Post #1839735
Posted Monday, December 5, 2016 7:32 AM
SSCrazy Eights

SSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy Eights

Group: General Forum Members
Last Login: Yesterday @ 6:45 AM
Points: 8,328, Visits: 858
John Mitchell-245523 (12/2/2016)
Or this:
ALTER DATABASE SQLTRIX SET SINGLE_USER WITH ROLLBACK IMMEDIATE

You can use RESTRICTED USER instead of SINGLE USER if that's more appropriate (in other words if none of the processes that are likely to connect to the database will do so as db_owner or higher).

John
Thanks for the tip.
Post #1840208
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse