如何强制 SQL Server 2008 数据库脱机

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3005662/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 06:29:38  来源:igfitidea点击:

How to force a SQL Server 2008 database to go Offline

sqlsql-servertsqlsql-server-2008

提问by radbyx

How do I force my Database to go Offline, without regard to what or who is already using it?

如何强制我的数据库脱机,而不考虑已经在使用它的内容或谁?

I tried:

我试过:

ALTER DATABASE database-name SET OFFLINE;

But it's still hanging after 7 min.

但是7分钟后它仍然挂着。

I want this because I need to test the scenario.

我想要这个,因为我需要测试场景。

If it's even possible?

如果有可能吗?

回答by abatishchev

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

回答by Martin Smith

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

您需要使用WITH ROLLBACK IMMEDIATE来启动其他连接,而无需考虑已经在使用什么或谁在使用它。

Or use WITH NO_WAITto not hang and not kill existing connections. See http://www.blackwasp.co.uk/SQLOffline.aspxfor details

或者用于WITH NO_WAIT不挂起并且不终止现有连接。有关详细信息,请参阅http://www.blackwasp.co.uk/SQLOffline.aspx