Solved

Killing spid's or processes on a sql server from the

Posted on 2016-08-11
4
36 Views
Last Modified: 2016-08-15
I often restore a version of a prod database on top of a test database.  Many times the test database will have active connections that i kill off with the activity monitor in ssms. (allowing the restore to proceed)  Would putting the database in single-user mode offer me the same results of killing all active connections.  what are the risks of putting it in single user mode?

proposed steps.  

put test database in single-user mode
restore production database to the test database.

will the test database be in single user mode after the restore.
0
Comment
Question by:jamesmetcalf74
4 Comments
 
LVL 20

Accepted Solution

by:
Russ Suter earned 250 total points
ID: 41753139
I don't think there's a real advantage to putting the DB into single user mode. If your current process of killing SPIDs is working just stick with that. The restore database dialog does have an option that lets you close connections before proceeding and it warns that it may put the DB into single user mode. However I've never had this happen and if it ever does it's a quick single line query to put it back in to multiuser mode.
DB Restore Options
0
 
LVL 26

Assisted Solution

by:Chris Luttrell
Chris Luttrell earned 125 total points
ID: 41753408
we use this statement all the time and it is what I see from many knowledgeable SQL people:
alter database xxx set single_user with rollback immediate

then do your restore and of course set it back to multi user as your last command
0
 
LVL 69

Assisted Solution

by:ScottPletcher
ScottPletcher earned 125 total points
ID: 41753932
I've had so many issues with trying to get dbs back out of SINGLE_USER mode that I force the db OFFLINE, then restore it.  That also absolutely prevents any new connection from occurring on the db.  By default, the restore puts it back ONLINE (at least in my experience so far, thru SQL 2012 (only)).

ALTER DATABASE [db_name] SET OFFLINE WITH ROLLBACK IMMEDIATE;
RESTORE DATABASE [db_name] ... WITH REPLACE, ...;
0
 

Author Closing Comment

by:jamesmetcalf74
ID: 41756847
thanks gentlemen
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

I wrote this interesting script that really help me find jobs or procedures when working in a huge environment. I could I have written it as a Procedure but then I would have to have it on each machine or have a link to a server-related search that …
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now