SQL Server Forums
Profile | Register | 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
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

sunny_10
Yak Posting Veteran

65 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

3554 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

571 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
788 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  
 New 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.06 seconds. Powered By: Snitz Forums 2000