简体   繁体   中英

Blocking within SSMS tab

This sutiation can be easily reproduced on your test environment. Open SSMS and connect to you server. Open New Query tab connected to MYTEST database (I assume that MYTEST is online). Don't do anything with this tab. Open new tab connected to the same database. Type the following code in your new tab

USE master
GO
ALTER DATABASE MYTEST
SET OFFLINE

Your code will be head blocked by the process you are running from your first tab.(Please see Activity Monitor). Why is the execution blocked even though there is no task accosiated with process in the first tab?

You'd need to tell SQL to kick every connection out

ALTER DATABASE MYTEST
SET OFFLINE
WITH ROLLBACK IMMEDIATE

This is by design : a connection to a database has shared DB lock, whether executing or not.

WITH <termination>::=

Specifies when to roll back incomplete transactions when the database is transitioned from one state to another. If the termination clause is omitted, the ALTER DATABASE statement waits indefinitely if there is any lock on the database. Only one termination clause can be specified, and it follows the SET clauses.

Just run sp_lock (or whatever the new dmvs are :-) and you'll see them

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM