Exit single-user mode

前端 未结 18 1053
离开以前
离开以前 2020-12-12 09:32

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

相关标签:
18条回答
  • 2020-12-12 10:15

    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
    
    0 讨论(0)
  • 2020-12-12 10:17

    Another option is to:

    • take the database offline; in SMSS, right click database and choose Take Offline, tick 'Drop all connections'
    • run ALTER DATABASE [Your_Db] SET MULTI_USER
    0 讨论(0)
  • 2020-12-12 10:17

    The 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
    
    0 讨论(0)
  • 2020-12-12 10:20

    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

    0 讨论(0)
  • 2020-12-12 10:21

    Use this Script

    exec sp_who
    

    Find the dbname and spid column

    now execute

    kill spid 
    go
    ALTER DATABASE [DBName]
    SET MULTI_USER;
    
    0 讨论(0)
  • 2020-12-12 10:21

    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!

    0 讨论(0)
提交回复
热议问题