SQL Server 2008 R2 卡在单用户模式

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24608702/
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 02:10:39  来源:igfitidea点击:

SQL Server 2008 R2 Stuck in Single User Mode

sqlsql-serverdatabasesql-server-2008database-deployment

提问by Paul Michaels

Having executed a DB deploy (from a VS SQL Server database project) on a local database, which failed, the database has been left in a state where it has single user mode left on (the deploy runs as single user mode).

在本地数据库上执行数据库部署(来自 VS SQL Server 数据库项目)失败后,该数据库一直处于单用户模式(部署作为单用户模式运行)的状态。

When I connect to it from SSMS and try something like the following:

当我从 SSMS 连接到它并尝试以下操作时:

ALTER DATABASE MyDatabase
SET MULTI_USER;
GO

I get the error:

我收到错误:

Changes to the state or options of database 'MyDatabase' cannot be made at this time. The database is in single-user mode, and a user is currently connected to it.

目前无法更改数据库“MyDatabase”的状态或选项。数据库处于单用户模式,当前有用户连接到它。

I tried taking the database offline, which SSMS tells me succeeds, but it doesn't appear to actually do anything. So far, I've only been able to get around this by dropping and recreating the database (which is kind of okay, because it's only a local test database). However, I'd like to be able to reset the status.

我尝试使数据库脱机,SSMS 告诉我它成功了,但它实际上似乎没有做任何事情。到目前为止,我只能通过删除和重新创建数据库来解决这个问题(这很好,因为它只是一个本地测试数据库)。但是,我希望能够重置状态。

How can I convince SQL Server to take this database out of single user mode?

如何说服 SQL Server 将该数据库从单用户模式中移除?

回答by mehdi lotfi

In first run following query in master database

在主数据库中第一次运行以下查询

exec sp_who

If you can't find the culprit, try

如果找不到罪魁祸首,请尝试

SELECT request_session_id FROM sys.dm_tran_locks 
WHERE resource_database_id = DB_ID('YourDatabase')

Then kill all process that use your database with following query:

然后通过以下查询终止使用您的数据库的所有进程:

KILL spid

Then run following query:

然后运行以下查询:

USE Master
ALTER DATABASE YourDatabase SET MULTI_USER

回答by Tristan

This was answered here, the code is:

这是回答here,代码是:

use master
ALTER DATABASE YourDatabase SET SINGLE_USER WITH ROLLBACK IMMEDIATE 

--do you stuff here 

ALTER DATABASE YourDatabase SET MULTI_USER

回答by Pankil Agrawal

Try the below commands

试试下面的命令

First run these three commands

首先运行这三个命令

USE [master] 
SET DEADLOCK_PRIORITY HIGH
exec sp_dboption MyDBName, 'single user', 'FALSE';

Second run these two commands

第二次运行这两个命令

ALTER DATABASE MyDBName SET MULTI_USER WITH NO_WAIT
ALTER DATABASE MyDBName SET MULTI_USER WITH ROLLBACK IMMEDIATE

回答by Youssef Ajrindou

To force the update use " with rollback immediate"

强制更新使用“立即回滚”

ALTER DATABASE [dataBase] SET MULTI_USER with rollback immediate

ALTER DATABASE [dataBase] SET MULTI_USER 立即回滚

回答by Ankit

Use DAC (Dedicated Admin Connection). Make sure you have enabled it first In SSMS type in admin: for Server Name after connecting to master ALTER DATABASE SET MULTI_USER

使用DAC(专用管理连接)。确保您已先启用它 在 SSMS 中输入 admin: for Server Name after connected to master ALTER DATABASE SET MULTI_USER