Please start any new threads on our new site at http://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Detach Database
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

sunny_10
Yak Posting Veteran

72 Posts

Posted - 05/01/2013 :  07:49:26  Show Profile  Reply with Quote
Hi

I am running this query but it gives error "Cannot detach database , because it is currently in use"

EXEC sp_detach_db @dbname = "Test01"

Thanks

James K
Flowing Fount of Yak Knowledge

3873 Posts

Posted - 05/01/2013 :  09:12:35  Show Profile  Reply with Quote
Run sp_who2 to see who is using the database. Also, if you are issuing the command while the current database is Test01, that can cause a problem as well. SO use
use master
GO
EXEC sp_detach_db @dbname = "Test01"
Go to Top of Page

Ifor
Aged Yak Warrior

700 Posts

Posted - 05/01/2013 :  09:37:04  Show Profile  Reply with Quote
It will probably be safer just to set the DB offline.


ALTER DATABASE Test01 SET OFFLINE WITH ROLLBACK IMMEDIATE;

Go to Top of Page

jeffw8713
Aged Yak Warrior

USA
819 Posts

Posted - 05/01/2013 :  14:17:19  Show Profile  Reply with Quote
quote:
Originally posted by Ifor

It will probably be safer just to set the DB offline.


ALTER DATABASE Test01 SET OFFLINE WITH ROLLBACK IMMEDIATE;





Depends on what the OP is trying to accomplish - although I do agree with your approach.
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.02 seconds. Powered By: Snitz Forums 2000