Currently, my database is in Single User mode. When I try to expand me database, I get an error:
The database \'my_db\' is not accessible.(ObjectExplo
Just in case if someone stumbles onto this thread then here is a bullet proof solution to SQL Server stuck in SINGLE USER MODE
-- Get the process ID (spid) of the connection you need to kill
-- Replace 'DBName' with the actual name of the DB
SELECT sd.[name], sp.spid, sp.login_time, sp.loginame
FROM sysprocesses sp
INNER JOIN sysdatabases sd on sp.dbid = sd.dbid
WHERE sd.[name] = 'DBName'
As an alternative, you can also use the command “sp_who” to get the “spid” of the open connection:
-- Or use this SP instead
exec sp_who
-- Then Execute the following and replace the [spid] and [DBName] with correct values
KILL SpidToKillGoesHere
GO
SET DEADLOCK_PRIORITY HIGH
GO
ALTER DATABASE [DBName] SET MULTI_USER WITH ROLLBACK IMMEDIATE
GO
Another option is to:
ALTER DATABASE [Your_Db] SET MULTI_USERThe following worked for me:
USE [master]
SET DEADLOCK_PRIORITY HIGH
exec sp_dboption '[StuckDB]', 'single user', 'FALSE';
ALTER DATABASE [StuckDB] SET MULTI_USER WITH NO_WAIT
ALTER DATABASE [StuckDB] SET MULTI_USER WITH ROLLBACK IMMEDIATE
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 = 'database name'
kill 568 -- kill spid
ALTER DATABASE database name'
SET MULTI_USER go
Use this Script
exec sp_who
Find the dbname and spid column
now execute
kill spid
go
ALTER DATABASE [DBName]
SET MULTI_USER;
Even I come across same problem, not able to find active connections to my_db to kill it but still shows same error. I end up disconnecting all possible SSMS connections for any database on the Server, create a new connection from SSMS and change it to Multi user.
-- Actual Code to change my_db to multi user mode
USE MASTER;
GO
ALTER DATABASE [my_db] SET MULTI_USER
Note: This seems to be a possible bug in SQL Server 2005!