Solved

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

Posted on 2016-08-11
4
52 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:Scott Pletcher
Scott Pletcher 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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

820 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