views:

84

answers:

2

How do I force my Database to go Offline, in no regards to what or who is is already using it?

I tried:

ALTER DATABASE database-name SET OFFLINE;

But it's still hanging of 7 min.

I want this because I need to test the scenario.

If it's even possible?

+3  A: 

You need to use WITH ROLLBACK IMMEDIATE to boot other conections out with no regards to what or who is is already using it.

Or use WITH NO_WAIT to not hang and not kill existing connections. See http://www.blackwasp.co.uk/SQLOffline.aspx for details

Martin Smith
+2  A: 

Go offline

USE master
GO
ALTER DATABASE YourDatabaseName
SET OFFLINE WITH ROLLBACK IMMEDIATE
GO

Go online

USE master
GO
ALTER DATABASE YourDatabaseName
SET ONLINE
GO
abatishchev
I would change 'master' to the "real" database-name thought.
radbyx
@radbyx: MSDN says to use `master` when operating DB's state
abatishchev
Allright nevermind then.
radbyx