Force SQL Server Database offline

If you right click a database in SSMS and select Tasks => Take Offline, you might find yourself staring at this dialog for hours, if there are active sessions running queries on your database.

Offline

Here’s how to force it to go offline, rolling back any current transactions. Replace [dbname] with the name of your database.

USE master
GO
ALTER DATABASE [dbname]
SET OFFLINE WITH ROLLBACK IMMEDIATE
GO

To get it back online, you can do this

USE master
GO
ALTER DATABASE [dbname]
SET ONLINE
GO

1 Comment

  • NONOadmin says:

    After watching SQL studio’s GUI hanging for half an hour this post was a life saver. Thank you!

Leave a Reply

Your email address will not be published. Required fields are marked *