SQL Server - How to display all SQL Statements of a sleeping uncommitted transaction?

Kumar, Sunil 6 Reputation points
2021-08-23T15:41:26.317+00:00

Often noticed applications execute SQL Statements within implicit transaction and end up in blocking other active sessions/transactions. The blocking session status would be SLEEPING, and AWAITING COMMAND. Most recent SQL statement of the blocking session ususally displays an unrelated SELECT statment on non-suspicious table/object. Though it is possible to identify the lockings on different underlying objects based on the session id, and the transaction id, is there a way find all the syntaxes of the blocking session in the same order in which they got executed, and the records affected by the statement, along with locking details? IS there any DMV that can list the activities of a sleeping transaction, or any such feature to be made available in future edition of SQL Server?

Developer technologies Transact-SQL
SQL Server Other
0 comments No comments
{count} vote

3 answers

Sort by: Most helpful
  1. Tom Phillips 17,771 Reputation points
    2021-08-23T16:13:59.697+00:00

  2. Erland Sommarskog 121.4K Reputation points MVP Volunteer Moderator
    2021-08-23T21:01:51.75+00:00

    Only, if you have set up a trace or extended-event session in advance. And I recommend against that, as tracing every statement being executed can be expensive and have a significant negative impact on the performance of the server.


  3. AmeliaGu-MSFT 14,006 Reputation points Microsoft External Staff
    2021-08-24T06:07:45.913+00:00

    Hi KumarSunil-0372,
    You can try to use sp_whoisactive.sql to help you find the sleeping and blocking transactions.
    Please refer to sp_whoisactive Documentation for more details.

    Best Regards,
    Amelia


    If the answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.