sql-serverdatabase-deadlocks

Deadlocks - Finding full SQL statement from deadlock report


I have an application running against a SQL Server 2016 database that is causing deadlocks.

The deadlock graph shows me the Objectid and Object name of the underlying object. It also provides with a truncated SQL statement.

However, some of the statements are quite big and exceed what appears to be a 1024 character limit in the XML deadlock report for the <inputbuf> entity. I'd like to be able to review the full statements involved in these locks so I can reproduce and debug the issue.

Is there a way this limit can be increased, or can is there a method to find the full SQL statement given the transaction descriptor which is included in the deadlock graph?


Solution

  • I found that I could obtain the full SQL text of each query in the deadlock using the SQL Handle string (the SQL Handle is included in the deadlock graph / XDL).

    For example, within the Deadlock XML:

    <frame procname="adhoc" line="1" stmtend="368" sqlhandle="0x02000000309a63065dbc0db09405222fe0f66eb954ed1d870000000000000000000000000000000000000000">
    

    Pass sqlhandle to sys.dm_exec_sql_text

     SELECT * FROM sys.dm_exec_sql_text(0x02000000309a63065dbc0db09405222fe0f66eb954ed1d870000000000000000000000000000000000000000000000000000000000000000000000000) -- modify this value with your actual sql_handle