Monday, June 6, 2022

SQL Server Database in Single User Model

 Some time you may have notice database status change to "Single User", Once database status changed to "single user" you will not be able to execute query on that database. Below is the solution to change the status of database to "MULTI_USER"

Solution :
SELECT request_session_id, * FROM sys.dm_tran_locks WHERE resource_database_id = DB_ID('databaseName')

Connect to Master database or any other database which is in open state, Copy request_session_id from above query and Kill the session using below command.


KILL request_session_id

USE master
GO
ALTER DATABASE databaseName SET MULTI_USER WITH ROLLBACK IMMEDIATE
GO
ALTER DATABASE databaseName SET online
Go


web stats