Question

I had a query that was being blocked. Ran sp_whoisactive @ get_locks=1 and identified the blocking query and it's owner. The result indicated the table had been locked for over four hours. The developer stated it was a stored procedure that she executed and it completed in 21 seconds. She still had the SSMS window open for the stored procedure. As soon as she closed the window the lock was released. I've never seen a completed stored procedure retain the lock simply because the window had not been closed. I've researched, but have been unable to find anything similar to this issue. The stored procedure basically Selects records into a temp table and then UPDATES another table and sets a flag if there is a bad address detected. Is this standard behavior? Is there a setting that can be changed so this does not happen?

It's SQL Server 2019. SSMS v 18.

Was it helpful?

Solution

Is this standard behavior?

No. There was either a transaction started before the stored procedure ran, or the session was running with SET IMPLICIT_TRANSACTIONS ON, which can be set to default for SSMS query windows.

In any case if the session was blocking with no query running, it had an open transaction.

OTHER TIPS

What David said, and also, when the window was closed the connection would have terminated and the open transaction would roll back. Any work done by that SP, all rows written by it, will be lost.

Licensed under: CC-BY-SA with attribution
Not affiliated with dba.stackexchange
scroll top