patternsqlMinor
Why is sql_text "select @@trancount" in open but sleeping transaction?
Viewed 0 times
whyopenbutsleepingsql_texttrancounttransactionselect
Problem
Using SQL Server Management Studio, open a query window and execute
In another window execute
I see
What's up with this? Who's counting transactions? Is this a Management Studio thing?
BEGIN TRANIn another window execute
select [text],
from sys.sysprocesses
cross apply sys.dm_exec_sql_text(sql_handle)
where status = 'sleeping'
and open_tran = 1I see
select @@trancountWhat's up with this? Who's counting transactions? Is this a Management Studio thing?
Solution
This is a SQL Server Management Studio thing. At least SSMS version 13.0.15500.91. This version of SSMS will count the number of open transactions on your behalf using the same connection as your query window.
Here's how I found out,
Here's how I found out,
- I connected to another server running 2012 and also saw
SELECT @@TRANCOUNT
- Using a 2012 version of SSMS, I connected to a variety of servers and saw
BEGIN TRAN
- I used profiler and saw that SSMS 2016 executes
SELECT @@TRANCOUNTafter every execution.
- Incidentally, SSMS 2016 seems to execute
SELECT SERVERPROPERTY('EngineEdition') AS DatabaseEngineEditionbefore every execution.
BEGIN TRANturns out to be a bit of a red herring. SSMS 2016 executes these extra queries no matter what gets executed in the query window... even if your batch is just whitespace.
- I coded an c# application that uses ado.net and profiled it. It does not execute these extra queries.
Context
StackExchange Database Administrators Q#146654, answer score: 3
Revisions (0)
No revisions yet.