Exit single-user mode

前端 未结 18 1064
离开以前
离开以前 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:09

    Adding to Jespers answer, to be even more effective:

    SET DEADLOCK_PRIORITY 10;-- Be the top dog.
    

    SET DEADLOCK_PRIORITY HIGH uses DEADLOCK_PRIORITY of 5.

    What is happening is that the other processes get a crack at the database and, if your process has a lower DEADLOCK_PRIORITY, then it loses the race.

    This obviates finding and killing the other spid (which might need to be done several times).

    It is possible that you would need to run ALTER DATABASE more than once, (but Jesper does that). Modified code:

    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
    

提交回复
热议问题