SQL Server – How to Restore DB to Multi-User Mode When Deadlocked by Sys Process

sql serversql-server-2012

I have a database that is stuck in Single User mode after a failed restore process. I have checked the sysprocesses table and none of the processes have spid > 50. They are all sa processes. Using the following code returns a deadlock that I can not seem to clear:

ALTER DATABASE myDatabase SET MULTI_USER with NO_WAIT

Besides restarting the SQL Server and then spamming the Alter statement, is there a way for me to pull this out of single user mode? Thanks in advance for any help you can provide.

Best Answer

Apart from what Shawan referenced, another option is to use DAC ADMIN:ServerName

then issue below command (note that I am not using NO_WAIT)

ALTER DATABASE database SET MULTI_USER with rollback immediate

From BOL :

ROLLBACK AFTER integer [SECONDS] | ROLLBACK IMMEDIATE

Specifies whether to roll back after the specified number of seconds or immediately.

NO_WAIT

Specifies that if the requested database state or option change cannot complete immediately without waiting for transactions to commit or roll back on their own, the request will fail.