开发者

Blocking within SSMS tab

开发者 https://www.devze.com 2023-02-11 03:03 出处:网络
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).

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开发者_如何学C 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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号