Method 1, DBCC OPENTRAN + sys.dm_exec_connections
DBCC OPENTRAN;
You can see that the driest activity was initiated by the 54 session. Let's take a look at what it does.
Select Conn.session_id,sess.program_name,sqltext.text
From Sys.dm_exec_connections as Conn cross apply Sys.dm_exec_sql_text (Conn.most_recent_sql_handle) as Sqltext,sys.dm_ Exec_sessions Sess
where conn.session_id = sess.session_id and conn.session_id = 54;
Go
Here you can see that session 54 is the last thing to do is ' SELECT @ @spid ' Remember the oldest activity transaction is 54 open? But this business is not open for @ @spid
Summarize:
DBCC OPENTRAN only returns the most active transaction, not the last transaction of the session, Sys.dm_exec_connections can only get the SQL code reference of the last transaction.
To find the oldest transaction what it is doing, this method still does not work.
SQL Server connection and transaction-related issues.