Tell me more ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

We need to do a restore, and cannot because other users are connected. We thought we had disconnected every process, but apparently not.

How can we, from Management Studio, kick off everyone else so we can do this backup?

share|improve this question
1  
See this question on Stack Overflow – Gaius Sep 21 '11 at 16:14

3 Answers

up vote 4 down vote accepted

There are two ways of doing it:

1) Right click on the database in Object Explorer go to Tasks > Detach. Select the Drop Connections checkbox.

2) Set the database to single-user mode as outlined here:

http://msdn.microsoft.com/en-us/library/ms345598.aspx

share|improve this answer
5  
For option 1 -> not directly detach, just select the drop connections option and then script the action. You'll have a script created by Management Studio that will either kill current sessions or will make db single-user (don't remember exactly which). And after generating this script just Cancel the Detach screen. – Marian Sep 22 '11 at 8:50

I always use:

ALTER DATABASE [dbname] SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
share|improve this answer

I use this code:

ALTER DATABASE [Dbname] set offline with rollback immediate
GO
ALTER DATABASE [Dbname] set online
GO

But I can see the SINGLE USER example is less to type.

share|improve this answer
1  
Also setting the database back online means other users can connect again before you start your restore. – Aaron Bertrand Jun 2 '12 at 16:04

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.