Extreme wait-time when taking a SQL Server database offline

前端 未结 17 913
有刺的猬
有刺的猬 2021-01-29 17:05

I\'m trying to perform some offline maintenance (dev database restore from live backup) on my dev database, but the \'Take Offline\' command via SQL Server Management Studio is

17条回答
  •  失恋的感觉
    2021-01-29 17:47

    After some additional searching (new search terms inspired by gbn's answer and u07ch's comment on KMike's answer) I found this, which completed successfully in 2 seconds:

    ALTER DATABASE  SET OFFLINE WITH ROLLBACK IMMEDIATE
    

    (Update)

    When this still fails with the following error, you can fix it as inspired by this blog post:

    ALTER DATABASE failed because a lock could not be placed on database 'dbname' Try again later.

    you can run the following command to find out who is keeping a lock on your database:

    EXEC sp_who2
    

    And use whatever SPID you find in the following command:

    KILL 
    

    Then run the ALTER DATABASE command again. It should now work.

提交回复
热议问题