I need to take a database offline immediately, but a latent connection is blocking the SET OFFLINE
operation. I attempted to take it offline from SQL Server Management Studio, which would have called ALTER DATABASE <database_name> SET OFFLINE
, instead of ALTER DATABASE <database_name> SET OFFLINE WITH NO-WAIT
like I should have.
Other attempts to access or take the database offline fail because a lock a cannot be obtained due to the blocking operation.
How can I cancel the blocking SET OFFLINE
operation without taking my entire instance offline?
Update: I ended up restarting my SQL Service instance, which quickly released the lock, but it was undesirable. I would still like to know how to kill the connections blocking a SET OFFLINE
operation.
The short answer is execute the following sql:
See this SO question for further info / links
You can't cancel the offline command: it will wait until it can od it's thing.
You can KILL the offending connection though.
You may be able to kill the ALTER DATABASE statement but IIRC it's already executed.
If you restart SQL Server the DB will be offline too.