Extreme wait-time when taking a SQL Server database offline

前端 未结 17 898
有刺的猬
有刺的猬 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:52

    In my case, after waiting so much for it to finish I had no patience and simply closed management studio. Before exiting, it showed the success message, db is offline. The files were available to rename.

    0 讨论(0)
  • 2021-01-29 17:52

    anytime you run into this type of thing you should always think of your transaction log. The alter db statment with rollback immediate indicates this to be the case. Check this out: http://msdn.microsoft.com/en-us/library/ms189085.aspx

    Bone up on checkpoints, etc. You need to decide if the transactions in your log are worth saving or not and then pick the mode to run your db in accordingly. There's really no reason for you to have to wait but also no reason for you to lose data either - you can have both.

    0 讨论(0)
  • 2021-01-29 17:54

    Also, close any query windows you may have open that are connected to the database in question ;)

    0 讨论(0)
  • 2021-01-29 17:54

    Next time, from the Take Offline dialog, remember to check the 'Drop All Active Connections' checkbox. I was also on SQL_EXPRESS on local machine with no connections, but this slowdown happened for me unless I checked that checkbox.

    0 讨论(0)
  • 2021-01-29 17:57

    In SSMS, set the database to read-only then back. The connections will be closed, which frees up the locks.

    In my case there was a website that had open connections to the database. This method was easy enough:

    1. Right-click the database -> Properties -> Options
    2. Set Database Read-Only to True
    3. Click 'Yes' at the dialog warning SQL Server will close all connections to the database.
    4. Re-open Options and turn read-only back off
    5. Now try renaming the database or taking it offline.
    0 讨论(0)
提交回复
热议问题