Single user mode issue

Sometimes ,mostly because you did something , your DB is stuck in a single user mode and you cannot connect to it anymore.

Below steps can help if you don’t know which user is connected to the DB.

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

It will return the process connected to the DB with PID
Then kill all process that use your database with following query:

KILL spid

Then run following query to change to multi user mode.

USE Master
ALTER DATABASE YourDatabase SET MULTI_USER

Advertisements