我需要帮助设置在SINGLE_USER模式恢复到MULTI_USER的数据库。每次我奔跑
ALTER DATABASE BARDABARD
SET MULTI_USER;
GO
我得到这个错误:
目前不能更改数据库'BARDABARD'的状态或选项。 数据库处于单用户模式,当前有用户连接到数据库。
它需要在非SINGLE_USER模式下将其设置为另一种模式,但当它是SINGLE_USER模式时,我不能将数据库设置为任何其他模式。
我需要帮助设置在SINGLE_USER模式恢复到MULTI_USER的数据库。每次我奔跑
ALTER DATABASE BARDABARD
SET MULTI_USER;
GO
我得到这个错误:
目前不能更改数据库'BARDABARD'的状态或选项。 数据库处于单用户模式,当前有用户连接到数据库。
它需要在非SINGLE_USER模式下将其设置为另一种模式,但当它是SINGLE_USER模式时,我不能将数据库设置为任何其他模式。
当前回答
SQL Server 2012:
右键单击DB > Properties > Options >[向下滚动]State > RestrictAccess >选择Multi_user,然后单击OK。
拖鞋!
其他回答
工作内容:
首先,我杀死所有数据库进程,以证明数据库没有在使用。 在我改变用户模式之后。
有时,一个进程会很快从应用程序中再次获取,我需要再次运行这个进程……
替换下面的表达式DATABASE_NAME,以使用您的数据库名称。
——杀过程
USE Master
GO
declare @sql as varchar(20), @spid as int
select @spid = min(spid) from master..sysprocesses where dbid = db_id('DATABASE_NAME') and spid != @@spid
while (@spid is not null)
begin
print 'Killing process ' + cast(@spid as varchar) + ' ...'
set @sql = 'kill ' + cast(@spid as varchar)
exec (@sql)
select
@spid = min(spid)
from
master..sysprocesses
where
spid > 50 AND dbid = db_id('DATABASE_NAME')
and spid != @@spid
end
print 'Killing Process completed...'
GO
**--Alter user mode**
ALTER DATABASE DATABASE_NAME SET MULTI_USER;
GO
print 'Alter Database Process completed...'
“用户当前连接到它”可能是SQL Server Management Studio窗口本身。尝试选择主数据库并再次运行ALTER查询。
我也有同样的问题,它通过以下步骤修复-参考:http://giladka8.blogspot.com.au/2011/11/database-is-in-single-user-mode-and.html
use master
GO
select
d.name,
d.dbid,
spid,
login_time,
nt_domain,
nt_username,
loginame
from sysprocesses p
inner join sysdatabases d
on p.dbid = d.dbid
where d.name = 'dbname'
GO
kill 56 --=> kill the number in spid field
GO
exec sp_dboption 'dbname', 'single user', 'FALSE'
GO
最好是直接登录到服务器上,而不是使用SQL Management Studio
确保您要设置为MULTI_USER的数据库的登录帐户为dbowner。如果可以,以sa身份登录(使用SQL server身份验证)
如果你的数据库被IIS使用,停止网站和使用它的应用程序池-这可能是连接的进程,阻止你设置为MULTI_USER
USE MASTER
GO
-- see if any process are using *your* database specifically
SELECT * from master.sys.sysprocesses
WHERE spid > 50 -- process spids < 50 are reserved by SQL - we're not interested in these
AND dbid=DB_ID ('YourDbNameHere')
-- if so, kill the process:
KILL n -- where 'n' is the 'spid' of the connected process as identified using query above
-- setting database to read only isn't generally necessary, but may help:
ALTER DATABASE YourDbNameHere
SET READ_ONLY;
GO
-- should work now:
ALTER DATABASE Appswiz SET MULTI_USER WITH ROLLBACK IMMEDIATE
如果你还有问题,请参考这里:
http://www.sqlservercentral.com/blogs/pearlknows/2014/04/07/help-i-m-stuck-in-single-user-mode-and-can-t-get-out/
作为最后的选择-如果你已经尝试了上面的所有方法,并且你已经绝望了,你可以尝试停止SQL server实例并重新启动它
我轻而易举地解决了这个问题
右键单击数据库名称,重命名它 更改后,右键单击数据库名称—>属性—>选项—>滚动限制性访问底部(SINGLE_USER到MULTI_USER) 现在,您可以再次将数据库重命名为您的旧名称。