14

Even though nothing is using it I am unable to detach a database because it is use.

Cannot detach the database 'DEMO' because it is currently in use.

I have tried rebooting and get the same message.

5 Answers 5

17
--Kick all users off of the database NOW
ALTER DATABASE YourDatabase SET SINGLE_USER WITH ROLLBACK IMMEDIATE

--Kick all but after 60 seconds
ALTER DATABASE YourDatabase SET SINGLE_USER WITH ROLLBACK AFTER 60 SECONDS

--restore connection to users
ALTER DATABASE YourDatabase SET MULTI_USER
13

Have you tried checking the "Drop Connections" box when you detach it?

3
  • I was hoping more for a query related solution. Server Management Studio Express very often causes my machine to blue screen. So I'm using a tool that just sends queries to the server. Commented Oct 20, 2009 at 17:54
  • A blue screen is usually related to hardware or OS-level problems, not to some very specific application such as a database management tool. I can't imagine why this particular program makes your machine crash, but this is definitely a symptom of some underlying serious problem.
    – Massimo
    Commented Oct 20, 2009 at 18:53
  • It is some combination of Visual Studio and Server Management Studio Express, because I have seen the behavior on 3 different workstations. It might be from running multiple versions of Visual Studio at once, I know this causes bizarre behavior in IE7 when using tabs. Commented Oct 28, 2009 at 18:30
1
  1. Disconnect from server.
  2. Restart the SQL Server service to close all connections.
  3. Log in with Windows Authentication.
  4. Easily detach the database.
1

Don't forget to check "Drop Connections" from "Detach Database" window, otherwise it's very simple and just choose detach from the menu, see the image below:

enter image description here

0

This command should drop all connections, then allow you to detach.

ALTER DATABASE SET SINGLE_USER WITH ROLLBACK_IMMEDIATE

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .