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.

Jack B Nimble
  • 1,505
  • 1
  • 10
  • 13

5 Answers5

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
RateControl
  • 1,207
  • 9
  • 20
12

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

joeqwerty
  • 108,377
  • 6
  • 80
  • 171
  • 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. – Jack B Nimble Oct 20 '09 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 Oct 20 '09 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. – Jack B Nimble Oct 28 '09 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.
Andrew Schulman
  • 8,561
  • 21
  • 31
  • 47
MSS
  • 181
  • 1
  • 3
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

Pierre.Vriens
  • 1,159
  • 34
  • 15
  • 19
0

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

ALTER DATABASE SET SINGLE_USER WITH ROLLBACK_IMMEDIATE

DanBig
  • 11,393
  • 1
  • 28
  • 53