简体   繁体   English

SQL Server 2008 R2 卡在单用户模式

[英]SQL Server 2008 R2 Stuck in Single User Mode

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.目前无法更改数据库“MyDatabase”的状态或选项。 The database is in single-user mode, and a user is currently connected to it.数据库处于单用户模式,当前有用户连接到它。

I tried taking the database offline, which SSMS tells me succeeds, but it doesn't appear to actually do anything.我尝试使数据库脱机,SSMS 告诉我它成功了,但它实际上似乎没有做任何事情。 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.但是,我希望能够重置状态。

How can I convince SQL Server to take this database out of single user mode?如何说服 SQL Server 将该数据库从单用户模式中移除?

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

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

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

Use DAC (Dedicated Admin Connection) .使用DAC(专用管理连接) Make sure you have enabled it first In SSMS type in admin: for Server Name after connecting to master ALTER DATABASE SET MULTI_USER确保您已先启用它 在 SSMS 中输入 admin: for Server Name after connected to master ALTER DATABASE SET MULTI_USER

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

ALTER DATABASE [DATABASE_NAME] SET MULTI_USER  with rollback immediate

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM