{"id":553,"date":"2010-12-11T22:46:00","date_gmt":"2010-12-11T22:46:00","guid":{"rendered":"\/blogs\/jonathan\/post\/An-XEvent-a-Day-(11-of-31)-e28093-Targets-Week-e28093-Using-Multiple-Targets-to-Debug-Orphaned-Transactions.aspx"},"modified":"2017-04-13T12:17:39","modified_gmt":"2017-04-13T16:17:39","slug":"an-xevent-a-day-11-of-31-targets-week-using-multiple-targets-to-debug-orphaned-transactions","status":"publish","type":"post","link":"https:\/\/www.sqlskills.com\/blogs\/jonathan\/an-xevent-a-day-11-of-31-targets-week-using-multiple-targets-to-debug-orphaned-transactions\/","title":{"rendered":"An XEvent a Day (11 of 31) \u2013 Targets Week \u2013 Using Multiple Targets to Debug Orphaned Transactions"},"content":{"rendered":"<p>Yesterday\u2019s blog post <a href=\"https:\/\/www.sqlskills.com\/blogs\/jonathan\/an-xevent-a-day-10-of-31-targets-week-etw_classic_sync_target\/\" target=\"_blank\">Targets Week \u2013 etw_classic_sync_target<\/a> covered the ETW integration that is built into Extended Events and how the etw_classic_sync_target can be used in conjunction with other ETW traces to provide troubleshooting at a level previously not possible with SQL Server.&#160; In today\u2019s post we\u2019ll look at how to use multiple targets to simplify analysis of Event collection.<\/p>\n<h2><\/h2>\n<h2>Why Multiple Targets?<\/h2>\n<p>You might ask why you would want to use multiple Targets in an Event Session with Extended Events?&#160; The best answer is because each of the Targets handles the Event data in different ways, and by combining their uses, you can easily simplify the task of tracking down problems.&#160; Two days ago I talked about the pair_matching Target and how it only retains Events that have not been matched.&#160; Two years ago out of nowhere, one of the production databases I supported started having transaction log growth problems.&#160; After growing the log for the second time in a day, I started looking at the database because something was obviously not right.&#160; <\/p>\n<p>The first place I looked was the sys.databases DMV and specifically the log_reuse_wait_desc column, which provides the reason that the transaction log for a database is not truncating.&#160; When I queried this DMV, I found that the log_reuse_wait_desc was ACTIVE_TRANSACTION, meaning that the database had an open transaction.&#160; So I ran DBCC OPENTRAN to get some more information about the open transaction (you can query the DMV\u2019s for this information as well) and found that the transaction had been open for over 8 hours.&#160; I queried sys.dm_exec_sessions for the session_id and found that the session was still being used and had submitted a request within the last minute, so it seemed to be an orphaned transaction.<\/p>\n<blockquote>\n<pre class=\"code\"><span style=\"color: blue\">SELECT \r\n    <\/span>session_id<span style=\"color: gray\">,\r\n    <\/span>login_time<span style=\"color: gray\">, \r\n    <\/span>last_request_start_time<span style=\"color: gray\">, \r\n    <\/span>last_request_end_time\r\n<span style=\"color: blue\">FROM <\/span><span style=\"color: green\">sys<\/span><span style=\"color: gray\">.<\/span><span style=\"color: green\">dm_exec_sessions\r\n<\/span><span style=\"color: blue\">WHERE <\/span>session_id <span style=\"color: gray\">= <\/span>76<\/pre>\n<\/blockquote>\n<p>After discussions with the Analyst for the application and the applications vendor, it was decided that the session should be killed forcing a ROLLBACK of the transaction and allowing the log to be truncate.&#160; (I\u2019ll discuss why this might prove be problematic later in this post)&#160; This resolved the problem, at least until the next day when the database began running out of space in the transaction log again, and once again had an open transaction that had been open for hours on a session that was sill being used by the application.&#160; What was really interesting was there was no correlation between the previous days open transactions begin time, and the begin time of the second occurrence of the problem, so it seemed to be a completely random occurrence which was not going to be easy to troubleshoot.&#160; <\/p>\n<p>I created a server side trace and tried over the next two days to figure out what the issue actually was, but didn\u2019t make much head way until I expanded the trace to have the statement starting and completed events along with the Errors and Warnings Events in the trace.&#160; When the problem reoccurred, I was able to read through the trace files using filtering to minimize the Trace Events captured down to the specific spid that held the open transaction and the events that occurred five minutes before and after the transaction_begin_time for the open transaction.&#160; While looking at the event information I found an Attention Event and was able to deduce what had happened. <\/p>\n<p>The application was a ASP.NET application, and the vendor used the CommandTimeout default which is 30 seconds.&#160; What happened was that a process was invoked that called a stored procedure to archive information from a transactional table into an archive table inside of the database, and the number of rows being archived caused the stored procedures execution to exceeded 30 seconds resulting in a timeout in the ASP.NET application, and the application silently handled the exception by doing nothing.&#160; The problem was that the stored procedure issued a BEGIN TRANSACTION before archiving the rows, and when the timeout occurred and the Attention Event was raised, the command aborted leaving the open transaction and creating the problem with the log not truncating.&#160; <\/p>\n<p>The connection was returned to the ASP.NET Connection Pool, and was constantly being reused by the application to do who knows what other operations, which is where killing the connection was potentially a very bad thing to do.&#160; All of the activity performed by this session was performed under the open transaction, so by killing the session, all of the activity would be rolled back.&#160; With no way to tell what exactly would be rolled back, killing the session should not be taken lightly.<\/p>\n<p>For the remainder of this post I am going to show a repro of this particular problem and how to use Multiple Targets in Extended Events to simplify the troubleshooting this.<\/p>\n<h2>Setting Up the Demo<\/h2>\n<p>To setup a reproduction of this problem you will need two instances of SSMS open.&#160; One of them will be used to connect to the SQL Server normally, and the other will be used to act like the ASP.NET application that originally had the problem.&#160; To setup the second instance of SSMS to act like the ASP.NET application, we are going to set the Execution Timeout using the Options of the Connect to Database Engine window, and we are also going to add an Additional Connection Parameter to the connection to set the Application Name on the connection to \u201cSome Poorly Written App\u201d as shown in the below screenshots from SSMS.<\/p>\n<p><a href=\"https:\/\/www.SQLskills.com\/blogs\/jonathan\/wp-content\/uploads\/windows-live-writer\/anxeventaday11of31targetsweekusingmulti\/50f1ca10\/image.png\"><img fetchpriority=\"high\" decoding=\"async\" style=\"border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px\" title=\"image\" border=\"0\" alt=\"image\" src=\"https:\/\/www.SQLskills.com\/blogs\/jonathan\/wp-content\/uploads\/windows-live-writer\/anxeventaday11of31targetsweekusingmulti\/53b77f03\/image_thumb.png\" width=\"414\" height=\"484\" \/><\/a>&#160;&#160; <a href=\"https:\/\/www.SQLskills.com\/blogs\/jonathan\/wp-content\/uploads\/windows-live-writer\/anxeventaday11of31targetsweekusingmulti\/2e4d8b95\/image.png\"><img decoding=\"async\" style=\"border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px\" title=\"image\" border=\"0\" alt=\"image\" src=\"https:\/\/www.SQLskills.com\/blogs\/jonathan\/wp-content\/uploads\/windows-live-writer\/anxeventaday11of31targetsweekusingmulti\/661fcfb8\/image_thumb.png\" width=\"414\" height=\"484\" \/><\/a> <\/p>\n<p>For the remainder of this blog post I am going to refer to the two different instances of SSMS as Normal and PoorApp in the hopes that this prevents confusion.&#160; <\/p>\n<p>In the Normal SSMS we will create a database and some objects to support the repro of the problem:<\/p>\n<blockquote>\n<pre class=\"code\"><span style=\"color: blue\">CREATE DATABASE <\/span>[MultiTargetDemo]\r\n<span style=\"color: blue\">GO\r\nUSE <\/span>[MultiTargetDemo]\r\n<span style=\"color: blue\">GO\r\nCREATE TABLE <\/span>dbo<span style=\"color: gray\">.<\/span>RandomObjectsArchive\r\n<span style=\"color: gray\">(<\/span>ArchiveID <span style=\"color: blue\">int identity primary key<\/span><span style=\"color: gray\">,\r\n <\/span>TableName <span style=\"color: blue\">nvarchar<\/span><span style=\"color: gray\">(<\/span>128<span style=\"color: gray\">),\r\n <\/span>IndexName <span style=\"color: blue\">nvarchar<\/span><span style=\"color: gray\">(<\/span>128<span style=\"color: gray\">),\r\n <\/span>ColumnName <span style=\"color: blue\">nvarchar<\/span><span style=\"color: gray\">(<\/span>128<span style=\"color: gray\">))\r\n<\/span><span style=\"color: blue\">GO\r\nCREATE TABLE <\/span>dbo<span style=\"color: gray\">.<\/span>TrackArchiveRunTimes\r\n<span style=\"color: gray\">(<\/span>RuntimeID <span style=\"color: blue\">int identity primary key<\/span><span style=\"color: gray\">,\r\n <\/span>ArchiveRuntime <span style=\"color: blue\">datetime DEFAULT<\/span><span style=\"color: gray\">(<\/span><span style=\"color: magenta\">CURRENT_TIMESTAMP<\/span><span style=\"color: gray\">))\r\n<\/span><span style=\"color: blue\">GO\r\nCREATE PROCEDURE <\/span>dbo<span style=\"color: gray\">.<\/span>GenerateRandomObjects\r\n<span style=\"color: blue\">AS\r\nBEGIN TRANSACTION\r\n    INSERT INTO <\/span>dbo<span style=\"color: gray\">.<\/span>TrackArchiveRunTimes\r\n    <span style=\"color: blue\">DEFAULT VALUES<\/span><span style=\"color: gray\">;\r\n\r\n    <\/span><span style=\"color: blue\">INSERT INTO <\/span>RandomObjectsArchive\r\n        <span style=\"color: gray\">(<\/span>TableName<span style=\"color: gray\">, <\/span>IndexName<span style=\"color: gray\">, <\/span>ColumnName<span style=\"color: gray\">)\r\n    <\/span><span style=\"color: blue\">SELECT TOP <\/span>10000 a<span style=\"color: gray\">.<\/span>name<span style=\"color: gray\">, <\/span>i<span style=\"color: gray\">.<\/span>name<span style=\"color: gray\">, <\/span>c<span style=\"color: gray\">.<\/span>name\r\n    <span style=\"color: blue\">FROM <\/span><span style=\"color: green\">sys<\/span><span style=\"color: gray\">.<\/span><span style=\"color: green\">objects <\/span><span style=\"color: blue\">AS <\/span>a\r\n        <span style=\"color: gray\">CROSS JOIN <\/span><span style=\"color: green\">sys<\/span><span style=\"color: gray\">.<\/span><span style=\"color: green\">indexes <\/span><span style=\"color: blue\">AS <\/span>i\r\n        <span style=\"color: gray\">CROSS JOIN <\/span><span style=\"color: green\">sys<\/span><span style=\"color: gray\">.<\/span><span style=\"color: green\">columns <\/span><span style=\"color: blue\">AS <\/span>c\r\n        <span style=\"color: gray\">CROSS JOIN <\/span><span style=\"color: blue\">master<\/span><span style=\"color: gray\">.<\/span>dbo<span style=\"color: gray\">.<\/span>spt_values <span style=\"color: blue\">AS <\/span>sv\r\n    <span style=\"color: blue\">WHERE <\/span>sv<span style=\"color: gray\">.<\/span><span style=\"color: blue\">type <\/span><span style=\"color: gray\">= <\/span><span style=\"color: red\">'P' \r\n      <\/span><span style=\"color: gray\">AND <\/span>sv<span style=\"color: gray\">.<\/span>number <span style=\"color: gray\">&lt; <\/span>6 <span style=\"color: green\">--Adjust to increase runtime\r\n    <\/span><span style=\"color: blue\">ORDER BY <\/span><span style=\"color: magenta\">NEWID<\/span><span style=\"color: gray\">() <\/span><span style=\"color: blue\">DESC\r\nCOMMIT TRANSACTION\r\nGO\r\nUSE <\/span>[master]\r\n<span style=\"color: blue\">GO<\/span><\/pre>\n<\/blockquote>\n<p>The GenerateRandomObjects stored procedure Inserts a row into a tracking table that tracks when the stored procedure was executed, and then simulates a long running archive process by doing something that you should never do in production code.&#160; The sv.number predicate in the query can be increased or decreased based on the performance of the system being tested against to ensure that the stored procedure runs longer than the Execution Timeout setting, which on my PoorApp SSMS instance was set to 10 seconds.&#160; Increasing the value by 1 has an exponential impact on the performance degradation of the stored procedure, so any changes should be made incrementally to ensure that you don\u2019t create a tempdb bloat problem with the Cartesian product of the query being executed.<\/p>\n<h2>Setting Up the Event Session<\/h2>\n<p>To troubleshoot this problem using Extended Events we will create an Event Session that captures the following Events:<\/p>\n<blockquote>\n<p>sqlserver.database_transaction_begin<br \/>\n    <br \/>sqlserver.database_transaction_end <\/p>\n<p>sqlserver.sql_statement_starting <\/p>\n<p>sqlserver.sql_statement_completed <\/p>\n<p>sqlserver.sp_statement_starting <\/p>\n<p>sqlserver.sp_statement_completed <\/p>\n<p>sqlserver.rpc_starting <\/p>\n<p>sqlserver.rpc_completed <\/p>\n<p>sqlserver.module_start <\/p>\n<p>sqlserver.module_end <\/p>\n<p>sqlserver.error_reported<\/p>\n<\/blockquote>\n<p>We\u2019ll add the following Actions to each of the Events:<\/p>\n<blockquote>\n<p>sqlserver.session_id<br \/>\n    <br \/>sqlserver.database_id <\/p>\n<p>sqlserver.tsql_stack<\/p>\n<\/blockquote>\n<p>and add the sqlserver.sql_text Action to the starting Events so that we can track what is actually being executed.&#160; Every Event in the Event Session will have a Predicate on the sqlserver.client_app_name so that the Event only fires for connections and requests from \u201cSome Poorly Written App\u201d.&#160; <\/p>\n<blockquote>\n<pre class=\"code\"><span style=\"color: blue\">IF <\/span><span style=\"color: gray\">EXISTS(<\/span><span style=\"color: blue\">SELECT <\/span><span style=\"color: gray\">* \r\n         <\/span><span style=\"color: blue\">FROM <\/span><span style=\"color: green\">sys<\/span><span style=\"color: gray\">.<\/span><span style=\"color: green\">server_event_sessions \r\n         <\/span><span style=\"color: blue\">WHERE <\/span>name<span style=\"color: gray\">=<\/span><span style=\"color: red\">'OrphanedTransactionHunter'<\/span><span style=\"color: gray\">) \r\n    <\/span><span style=\"color: blue\">DROP EVENT SESSION <\/span>[OrphanedTransactionHunter] <span style=\"color: blue\">ON SERVER<\/span><span style=\"color: gray\">; \r\n<\/span><span style=\"color: blue\">CREATE EVENT SESSION <\/span>OrphanedTransactionHunter\r\n<span style=\"color: blue\">ON SERVER\r\nADD EVENT <\/span>sqlserver<span style=\"color: gray\">.<\/span>database_transaction_begin\r\n<span style=\"color: gray\">(    <\/span><span style=\"color: blue\">ACTION<\/span><span style=\"color: gray\">(<\/span>sqlserver<span style=\"color: gray\">.<\/span>session_id<span style=\"color: gray\">, <\/span>sqlserver<span style=\"color: gray\">.<\/span>database_id<span style=\"color: gray\">, <\/span>sqlserver<span style=\"color: gray\">.<\/span>tsql_stack<span style=\"color: gray\">)\r\n    <\/span><span style=\"color: blue\">WHERE <\/span><span style=\"color: gray\">(<\/span>sqlserver<span style=\"color: gray\">.<\/span>client_app_name <span style=\"color: gray\">= <\/span><span style=\"color: red\">'Some Poorly Written App'<\/span><span style=\"color: gray\">)),\r\n<\/span><span style=\"color: blue\">ADD EVENT <\/span>sqlserver<span style=\"color: gray\">.<\/span>database_transaction_end\r\n<span style=\"color: gray\">(    <\/span><span style=\"color: blue\">ACTION<\/span><span style=\"color: gray\">(<\/span>sqlserver<span style=\"color: gray\">.<\/span>session_id<span style=\"color: gray\">, <\/span>sqlserver<span style=\"color: gray\">.<\/span>database_id<span style=\"color: gray\">, <\/span>sqlserver<span style=\"color: gray\">.<\/span>tsql_stack<span style=\"color: gray\">)\r\n    <\/span><span style=\"color: blue\">WHERE <\/span><span style=\"color: gray\">(<\/span>sqlserver<span style=\"color: gray\">.<\/span>client_app_name <span style=\"color: gray\">= <\/span><span style=\"color: red\">'Some Poorly Written App'<\/span><span style=\"color: gray\">)),\r\n<\/span><span style=\"color: blue\">ADD EVENT <\/span>sqlserver<span style=\"color: gray\">.<\/span>sql_statement_starting\r\n<span style=\"color: gray\">(    <\/span><span style=\"color: blue\">ACTION<\/span><span style=\"color: gray\">(<\/span>sqlserver<span style=\"color: gray\">.<\/span>session_id<span style=\"color: gray\">, <\/span>sqlserver<span style=\"color: gray\">.<\/span>database_id<span style=\"color: gray\">, <\/span>sqlserver<span style=\"color: gray\">.<\/span>tsql_stack<span style=\"color: gray\">, <\/span>sqlserver<span style=\"color: gray\">.<\/span>sql_text<span style=\"color: gray\">)\r\n    <\/span><span style=\"color: blue\">WHERE <\/span><span style=\"color: gray\">(<\/span>sqlserver<span style=\"color: gray\">.<\/span>client_app_name <span style=\"color: gray\">= <\/span><span style=\"color: red\">'Some Poorly Written App'<\/span><span style=\"color: gray\">)),\r\n<\/span><span style=\"color: blue\">ADD EVENT <\/span>sqlserver<span style=\"color: gray\">.<\/span>sql_statement_completed\r\n<span style=\"color: gray\">(    <\/span><span style=\"color: blue\">ACTION<\/span><span style=\"color: gray\">(<\/span>sqlserver<span style=\"color: gray\">.<\/span>session_id<span style=\"color: gray\">, <\/span>sqlserver<span style=\"color: gray\">.<\/span>database_id<span style=\"color: gray\">, <\/span>sqlserver<span style=\"color: gray\">.<\/span>tsql_stack<span style=\"color: gray\">)\r\n    <\/span><span style=\"color: blue\">WHERE <\/span><span style=\"color: gray\">(<\/span>sqlserver<span style=\"color: gray\">.<\/span>client_app_name <span style=\"color: gray\">= <\/span><span style=\"color: red\">'Some Poorly Written App'<\/span><span style=\"color: gray\">)),\r\n<\/span><span style=\"color: blue\">ADD EVENT <\/span>sqlserver<span style=\"color: gray\">.<\/span>sp_statement_starting\r\n<span style=\"color: gray\">(    <\/span><span style=\"color: blue\">ACTION<\/span><span style=\"color: gray\">(<\/span>sqlserver<span style=\"color: gray\">.<\/span>session_id<span style=\"color: gray\">, <\/span>sqlserver<span style=\"color: gray\">.<\/span>database_id<span style=\"color: gray\">, <\/span>sqlserver<span style=\"color: gray\">.<\/span>tsql_stack<span style=\"color: gray\">, <\/span>sqlserver<span style=\"color: gray\">.<\/span>sql_text<span style=\"color: gray\">)\r\n    <\/span><span style=\"color: blue\">WHERE <\/span><span style=\"color: gray\">(<\/span>sqlserver<span style=\"color: gray\">.<\/span>client_app_name <span style=\"color: gray\">= <\/span><span style=\"color: red\">'Some Poorly Written App'<\/span><span style=\"color: gray\">)),\r\n<\/span><span style=\"color: blue\">ADD EVENT <\/span>sqlserver<span style=\"color: gray\">.<\/span>sp_statement_completed\r\n<span style=\"color: gray\">(    <\/span><span style=\"color: blue\">ACTION<\/span><span style=\"color: gray\">(<\/span>sqlserver<span style=\"color: gray\">.<\/span>session_id<span style=\"color: gray\">, <\/span>sqlserver<span style=\"color: gray\">.<\/span>database_id<span style=\"color: gray\">, <\/span>sqlserver<span style=\"color: gray\">.<\/span>tsql_stack<span style=\"color: gray\">)\r\n    <\/span><span style=\"color: blue\">WHERE <\/span><span style=\"color: gray\">(<\/span>sqlserver<span style=\"color: gray\">.<\/span>client_app_name <span style=\"color: gray\">= <\/span><span style=\"color: red\">'Some Poorly Written App'<\/span><span style=\"color: gray\">)),\r\n<\/span><span style=\"color: blue\">ADD EVENT <\/span>sqlserver<span style=\"color: gray\">.<\/span>rpc_starting\r\n<span style=\"color: gray\">(    <\/span><span style=\"color: blue\">ACTION<\/span><span style=\"color: gray\">(<\/span>sqlserver<span style=\"color: gray\">.<\/span>session_id<span style=\"color: gray\">, <\/span>sqlserver<span style=\"color: gray\">.<\/span>database_id<span style=\"color: gray\">, <\/span>sqlserver<span style=\"color: gray\">.<\/span>tsql_stack<span style=\"color: gray\">, <\/span>sqlserver<span style=\"color: gray\">.<\/span>sql_text<span style=\"color: gray\">)\r\n    <\/span><span style=\"color: blue\">WHERE <\/span><span style=\"color: gray\">(<\/span>sqlserver<span style=\"color: gray\">.<\/span>client_app_name <span style=\"color: gray\">= <\/span><span style=\"color: red\">'Some Poorly Written App'<\/span><span style=\"color: gray\">)),\r\n<\/span><span style=\"color: blue\">ADD EVENT <\/span>sqlserver<span style=\"color: gray\">.<\/span>rpc_completed\r\n<span style=\"color: gray\">(    <\/span><span style=\"color: blue\">ACTION<\/span><span style=\"color: gray\">(<\/span>sqlserver<span style=\"color: gray\">.<\/span>session_id<span style=\"color: gray\">, <\/span>sqlserver<span style=\"color: gray\">.<\/span>database_id<span style=\"color: gray\">, <\/span>sqlserver<span style=\"color: gray\">.<\/span>tsql_stack<span style=\"color: gray\">)\r\n    <\/span><span style=\"color: blue\">WHERE <\/span><span style=\"color: gray\">(<\/span>sqlserver<span style=\"color: gray\">.<\/span>client_app_name <span style=\"color: gray\">= <\/span><span style=\"color: red\">'Some Poorly Written App'<\/span><span style=\"color: gray\">)),\r\n<\/span><span style=\"color: blue\">ADD EVENT <\/span>sqlserver<span style=\"color: gray\">.<\/span>module_start\r\n<span style=\"color: gray\">(    <\/span><span style=\"color: blue\">ACTION<\/span><span style=\"color: gray\">(<\/span>sqlserver<span style=\"color: gray\">.<\/span>session_id<span style=\"color: gray\">, <\/span>sqlserver<span style=\"color: gray\">.<\/span>database_id<span style=\"color: gray\">, <\/span>sqlserver<span style=\"color: gray\">.<\/span>tsql_stack<span style=\"color: gray\">, <\/span>sqlserver<span style=\"color: gray\">.<\/span>sql_text<span style=\"color: gray\">)\r\n    <\/span><span style=\"color: blue\">WHERE <\/span><span style=\"color: gray\">(<\/span>sqlserver<span style=\"color: gray\">.<\/span>client_app_name <span style=\"color: gray\">= <\/span><span style=\"color: red\">'Some Poorly Written App'<\/span><span style=\"color: gray\">)),\r\n<\/span><span style=\"color: blue\">ADD EVENT <\/span>sqlserver<span style=\"color: gray\">.<\/span>module_end\r\n<span style=\"color: gray\">(    <\/span><span style=\"color: blue\">ACTION<\/span><span style=\"color: gray\">(<\/span>sqlserver<span style=\"color: gray\">.<\/span>session_id<span style=\"color: gray\">, <\/span>sqlserver<span style=\"color: gray\">.<\/span>database_id<span style=\"color: gray\">, <\/span>sqlserver<span style=\"color: gray\">.<\/span>tsql_stack<span style=\"color: gray\">)\r\n    <\/span><span style=\"color: blue\">WHERE <\/span><span style=\"color: gray\">(<\/span>sqlserver<span style=\"color: gray\">.<\/span>client_app_name <span style=\"color: gray\">= <\/span><span style=\"color: red\">'Some Poorly Written App'<\/span><span style=\"color: gray\">)),\r\n<\/span><span style=\"color: blue\">ADD EVENT <\/span>sqlserver<span style=\"color: gray\">.<\/span>error_reported\r\n<span style=\"color: gray\">(    <\/span><span style=\"color: blue\">ACTION<\/span><span style=\"color: gray\">(<\/span>sqlserver<span style=\"color: gray\">.<\/span>session_id<span style=\"color: gray\">, <\/span>sqlserver<span style=\"color: gray\">.<\/span>database_id<span style=\"color: gray\">, <\/span>sqlserver<span style=\"color: gray\">.<\/span>tsql_stack<span style=\"color: gray\">)\r\n    <\/span><span style=\"color: blue\">WHERE <\/span><span style=\"color: gray\">(<\/span>sqlserver<span style=\"color: gray\">.<\/span>client_app_name <span style=\"color: gray\">= <\/span><span style=\"color: red\">'Some Poorly Written App'<\/span><span style=\"color: gray\">))\r\n<\/span><span style=\"color: blue\">ADD TARGET <\/span>package0<span style=\"color: gray\">.<\/span>ring_buffer<span style=\"color: gray\">,\r\n<\/span><span style=\"color: blue\">ADD TARGET <\/span>package0<span style=\"color: gray\">.<\/span>pair_matching\r\n<span style=\"color: gray\">( <\/span><span style=\"color: blue\">SET <\/span>begin_event <span style=\"color: gray\">= <\/span><span style=\"color: red\">'sqlserver.database_transaction_begin'<\/span><span style=\"color: gray\">,\r\n      <\/span>begin_matching_actions <span style=\"color: gray\">= <\/span><span style=\"color: red\">'sqlserver.session_id'<\/span><span style=\"color: gray\">,\r\n      <\/span>end_event <span style=\"color: gray\">= <\/span><span style=\"color: red\">'sqlserver.database_transaction_end'<\/span><span style=\"color: gray\">,\r\n      <\/span>end_matching_actions <span style=\"color: gray\">= <\/span><span style=\"color: red\">'sqlserver.session_id'<\/span><span style=\"color: gray\">,\r\n      <\/span>respond_to_memory_pressure <span style=\"color: gray\">= <\/span>1\r\n<span style=\"color: gray\">)\r\n<\/span><span style=\"color: blue\">WITH <\/span><span style=\"color: gray\">(<\/span>MAX_DISPATCH_LATENCY<span style=\"color: gray\">=<\/span>5 SECONDS<span style=\"color: gray\">, <\/span>TRACK_CAUSALITY<span style=\"color: gray\">=<\/span><span style=\"color: blue\">ON<\/span><span style=\"color: gray\">)\r\n<\/span><span style=\"color: blue\">GO\r\n\r\nALTER EVENT SESSION <\/span>OrphanedTransactionHunter\r\n<span style=\"color: blue\">ON SERVER\r\nSTATE<\/span><span style=\"color: gray\">=<\/span>START\r\n<span style=\"color: blue\">GO<\/span><\/pre>\n<\/blockquote>\n<p>Fired Events will be dispatched to two different Targets, the package0.ring_buffer to capture the Raw Data (in a true production environment, the package0.asynchronous_file_target would generally be a better Target for Raw Data capture of any volume), and the package0.pair_matching Target which has been configured to match on the sqlserver.database_transaction_begin\/end Events based on the sqlserver.session_id Action.&#160; To ensure that we can track the relationship between events, the Event Session will have TRACK_CAUSALITY set to ON, and to minimize the time it takes for Events to be dispatched for our test, the MAX_DISPATCH_LATENCY will be set to 5 seconds.<\/p>\n<h2>Putting It All Together<\/h2>\n<p>With the Event Session running, we can change over to our PoorApp SSMS instance and execute the GenerateRandomObjects stored procedure inside of the MultiTargetDemo database.<\/p>\n<blockquote>\n<pre class=\"code\"><span style=\"color: blue\">EXECUTE <\/span>MultiTargetDemo<span style=\"color: gray\">.<\/span>dbo<span style=\"color: gray\">.<\/span>GenerateRandomObjects<\/pre>\n<\/blockquote>\n<p>When this executes, the command will timeout and leave the transaction open, simulating the original problem exactly.&#160; Once the query times out, switch back to the Normal SSMS Instance and in a new window execute the stored procedure again and allow it complete its execution.&#160; Since the default timeout of 0 is used in the Normal SSMS Instance, the execution will not time out.&#160; Then we can look at the sys.databases DMV and see that the log_reuse_wait_desc is ACTIVE_TRANSACTION.<\/p>\n<blockquote><\/blockquote>\n<blockquote>\n<pre class=\"code\"><span style=\"color: blue\">SELECT <\/span>log_reuse_wait_desc \r\n<span style=\"color: blue\">FROM <\/span><span style=\"color: green\">sys<\/span><span style=\"color: gray\">.<\/span><span style=\"color: green\">databases\r\n<\/span><span style=\"color: blue\">WHERE <\/span>database_id <span style=\"color: gray\">= <\/span><span style=\"color: magenta\">DB_ID<\/span><span style=\"color: gray\">(<\/span><span style=\"color: red\">'MultiTargetDemo'<\/span><span style=\"color: gray\">)<\/span><\/pre>\n<\/blockquote>\n<blockquote>\n<p><a href=\"https:\/\/www.SQLskills.com\/blogs\/jonathan\/wp-content\/uploads\/windows-live-writer\/anxeventaday11of31targetsweekusingmulti\/7004c123\/image.png\"><img decoding=\"async\" style=\"border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px\" title=\"image\" border=\"0\" alt=\"image\" src=\"https:\/\/www.SQLskills.com\/blogs\/jonathan\/wp-content\/uploads\/windows-live-writer\/anxeventaday11of31targetsweekusingmulti\/1d85e0e7\/image_thumb.png\" width=\"191\" height=\"81\" \/><\/a> <\/p>\n<\/blockquote>\n<p>If we look at DBCC OPENTRAN for the MultiTargetDemo database we will see our orphaned transaction:<\/p>\n<blockquote>\n<pre class=\"code\"><span style=\"color: blue\">DBCC <\/span>OPENTRAN<span style=\"color: gray\">(<\/span>[MultiTargetDemo]<span style=\"color: gray\">)<\/span><\/pre>\n<\/blockquote>\n<blockquote>\n<p><a href=\"https:\/\/www.SQLskills.com\/blogs\/jonathan\/wp-content\/uploads\/windows-live-writer\/anxeventaday11of31targetsweekusingmulti\/4b0700aa\/image.png\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" style=\"border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px\" title=\"image\" border=\"0\" alt=\"image\" src=\"https:\/\/www.SQLskills.com\/blogs\/jonathan\/wp-content\/uploads\/windows-live-writer\/anxeventaday11of31targetsweekusingmulti\/5558250a\/image_thumb.png\" width=\"644\" height=\"202\" \/><\/a> <\/p>\n<\/blockquote>\n<p>As I mentioned earlier in this post, the transaction can also be seen in the DMV\u2019s:<\/p>\n<blockquote>\n<pre class=\"code\"><span style=\"color: blue\">SELECT \r\n    <\/span>dtst<span style=\"color: gray\">.<\/span>session_id<span style=\"color: gray\">, \r\n    <\/span>dtdt<span style=\"color: gray\">.<\/span>database_id<span style=\"color: gray\">,\r\n    <\/span>dtst<span style=\"color: gray\">.<\/span>transaction_id<span style=\"color: gray\">, \r\n    <\/span>dtat<span style=\"color: gray\">.<\/span>name<span style=\"color: gray\">,\r\n    <\/span>dtdt<span style=\"color: gray\">.<\/span>database_transaction_begin_time\r\n<span style=\"color: blue\">FROM <\/span><span style=\"color: green\">sys<\/span><span style=\"color: gray\">.<\/span><span style=\"color: green\">dm_tran_session_transactions <\/span><span style=\"color: blue\">AS <\/span>dtst\r\n<span style=\"color: gray\">JOIN <\/span><span style=\"color: green\">sys<\/span><span style=\"color: gray\">.<\/span><span style=\"color: green\">dm_tran_active_transactions <\/span><span style=\"color: blue\">AS <\/span>dtat\r\n    <span style=\"color: blue\">ON <\/span>dtst<span style=\"color: gray\">.<\/span>transaction_id <span style=\"color: gray\">= <\/span>dtat<span style=\"color: gray\">.<\/span>transaction_id\r\n<span style=\"color: gray\">JOIN <\/span><span style=\"color: green\">sys<\/span><span style=\"color: gray\">.<\/span><span style=\"color: green\">dm_tran_database_transactions <\/span><span style=\"color: blue\">AS <\/span>dtdt\r\n    <span style=\"color: blue\">ON <\/span>dtdt<span style=\"color: gray\">.<\/span>transaction_id <span style=\"color: gray\">= <\/span>dtst<span style=\"color: gray\">.<\/span>transaction_id\r\n<span style=\"color: blue\">WHERE <\/span>database_id <span style=\"color: gray\">= <\/span><span style=\"color: magenta\">DB_ID<\/span><span style=\"color: gray\">(<\/span><span style=\"color: red\">'MultiTargetDemo'<\/span><span style=\"color: gray\">)<\/span><\/pre>\n<\/blockquote>\n<blockquote>\n<p><a href=\"https:\/\/www.SQLskills.com\/blogs\/jonathan\/wp-content\/uploads\/windows-live-writer\/anxeventaday11of31targetsweekusingmulti\/293b2819\/image.png\"><img loading=\"lazy\" decoding=\"async\" style=\"border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px\" title=\"image\" border=\"0\" alt=\"image\" src=\"https:\/\/www.SQLskills.com\/blogs\/jonathan\/wp-content\/uploads\/windows-live-writer\/anxeventaday11of31targetsweekusingmulti\/3aab88f1\/image_thumb.png\" width=\"549\" height=\"82\" \/><\/a> <\/p>\n<\/blockquote>\n<p>Now that we have our problem reproduced, lets look at how we can use the information captured by our Extended Event Session to track it back to the source of the problem.&#160; First we\u2019ll query the pair_matching Target to find out information about the sqlserver.database_transaction_begin Event that was unmatched.<\/p>\n<blockquote>\n<pre class=\"code\"><span style=\"color: green\">-- Query the XML to get the Target Data\r\n<\/span><span style=\"color: blue\">SELECT \r\n    <\/span>n<span style=\"color: gray\">.<\/span>value<span style=\"color: gray\">(<\/span><span style=\"color: red\">'(event\/@name)[1]'<\/span><span style=\"color: gray\">, <\/span><span style=\"color: red\">'varchar(50)'<\/span><span style=\"color: gray\">) <\/span><span style=\"color: blue\">AS <\/span>event_name<span style=\"color: gray\">,\r\n    <\/span>n<span style=\"color: gray\">.<\/span>value<span style=\"color: gray\">(<\/span><span style=\"color: red\">'(event\/@package)[1]'<\/span><span style=\"color: gray\">, <\/span><span style=\"color: red\">'varchar(50)'<\/span><span style=\"color: gray\">) <\/span><span style=\"color: blue\">AS <\/span>package_name<span style=\"color: gray\">,\r\n    <\/span><span style=\"color: magenta\">DATEADD<\/span><span style=\"color: gray\">(<\/span>hh<span style=\"color: gray\">, \r\n            <\/span><span style=\"color: magenta\">DATEDIFF<\/span><span style=\"color: gray\">(<\/span>hh<span style=\"color: gray\">, <\/span><span style=\"color: magenta\">GETUTCDATE<\/span><span style=\"color: gray\">(), <\/span><span style=\"color: magenta\">CURRENT_TIMESTAMP<\/span><span style=\"color: gray\">), \r\n            <\/span>n<span style=\"color: gray\">.<\/span>value<span style=\"color: gray\">(<\/span><span style=\"color: red\">'(event\/@timestamp)[1]'<\/span><span style=\"color: gray\">, <\/span><span style=\"color: red\">'datetime2'<\/span><span style=\"color: gray\">)) <\/span><span style=\"color: blue\">AS <\/span>[timestamp]<span style=\"color: gray\">,\r\n    <\/span>n<span style=\"color: gray\">.<\/span>value<span style=\"color: gray\">(<\/span><span style=\"color: red\">'(event\/action[@name=&quot;session_id&quot;]\/value)[1]'<\/span><span style=\"color: gray\">, <\/span><span style=\"color: red\">'int'<\/span><span style=\"color: gray\">) <\/span><span style=\"color: blue\">as <\/span>session_id<span style=\"color: gray\">,\r\n    <\/span>n<span style=\"color: gray\">.<\/span>value<span style=\"color: gray\">(<\/span><span style=\"color: red\">'(event\/action[@name=&quot;database_id&quot;]\/value)[1]'<\/span><span style=\"color: gray\">, <\/span><span style=\"color: red\">'int'<\/span><span style=\"color: gray\">) <\/span><span style=\"color: blue\">as <\/span>[database_id]<span style=\"color: gray\">,\r\n    <\/span>n<span style=\"color: gray\">.<\/span>value<span style=\"color: gray\">(<\/span><span style=\"color: red\">'(event\/action[@name=&quot;tsql_stack&quot;]\/value)[1]'<\/span><span style=\"color: gray\">, <\/span><span style=\"color: red\">'nvarchar(max)'<\/span><span style=\"color: gray\">) <\/span><span style=\"color: blue\">as <\/span>tsql_stack<span style=\"color: gray\">,    \r\n    <\/span>n<span style=\"color: gray\">.<\/span>value<span style=\"color: gray\">(<\/span><span style=\"color: red\">'(event\/action[@name=&quot;attach_activity_id&quot;]\/value)[1]'<\/span><span style=\"color: gray\">, <\/span><span style=\"color: red\">'varchar(50)'<\/span><span style=\"color: gray\">) <\/span><span style=\"color: blue\">as <\/span>attach_activity_id\r\n<span style=\"color: blue\">FROM\r\n<\/span><span style=\"color: gray\">(    <\/span><span style=\"color: blue\">SELECT <\/span>td<span style=\"color: gray\">.<\/span>query<span style=\"color: gray\">(<\/span><span style=\"color: red\">'.'<\/span><span style=\"color: gray\">) <\/span><span style=\"color: blue\">as <\/span>n\r\n    <span style=\"color: blue\">FROM \r\n    <\/span><span style=\"color: gray\">(\r\n        <\/span><span style=\"color: blue\">SELECT <\/span><span style=\"color: magenta\">CAST<\/span><span style=\"color: gray\">(<\/span>target_data <span style=\"color: blue\">AS XML<\/span><span style=\"color: gray\">) <\/span><span style=\"color: blue\">as <\/span>target_data\r\n        <span style=\"color: blue\">FROM <\/span><span style=\"color: green\">sys<\/span><span style=\"color: gray\">.<\/span><span style=\"color: green\">dm_xe_sessions <\/span><span style=\"color: blue\">AS <\/span>s \r\n        <span style=\"color: gray\">JOIN <\/span><span style=\"color: green\">sys<\/span><span style=\"color: gray\">.<\/span><span style=\"color: green\">dm_xe_session_targets <\/span><span style=\"color: blue\">AS <\/span>t \r\n            <span style=\"color: blue\">ON <\/span>t<span style=\"color: gray\">.<\/span>event_session_address <span style=\"color: gray\">= <\/span>s<span style=\"color: gray\">.<\/span><span style=\"color: blue\">address\r\n        WHERE <\/span>s<span style=\"color: gray\">.<\/span>name <span style=\"color: gray\">= <\/span><span style=\"color: red\">'OrphanedTransactionHunter'\r\n          <\/span><span style=\"color: gray\">AND <\/span>t<span style=\"color: gray\">.<\/span>target_name <span style=\"color: gray\">= <\/span><span style=\"color: red\">'pair_matching'\r\n    <\/span><span style=\"color: gray\">) <\/span><span style=\"color: blue\">AS <\/span>sub\r\n    <span style=\"color: gray\">CROSS APPLY <\/span>target_data<span style=\"color: gray\">.<\/span>nodes<span style=\"color: gray\">(<\/span><span style=\"color: red\">'PairingTarget\/event'<\/span><span style=\"color: gray\">) <\/span><span style=\"color: blue\">AS <\/span>q<span style=\"color: gray\">(<\/span>td<span style=\"color: gray\">)\r\n) <\/span><span style=\"color: blue\">as <\/span>tab\r\n<span style=\"color: green\">-- We are interested in unmatched sqlserver.database_transaction_begin Events\r\n<\/span><span style=\"color: blue\">WHERE <\/span>n<span style=\"color: gray\">.<\/span>value<span style=\"color: gray\">(<\/span><span style=\"color: red\">'(event\/@name)[1]'<\/span><span style=\"color: gray\">, <\/span><span style=\"color: red\">'varchar(50)'<\/span><span style=\"color: gray\">) = <\/span><span style=\"color: red\">'database_transaction_begin'\r\n<\/span><span style=\"color: blue\">ORDER BY <\/span>session_id<span style=\"color: gray\">, <\/span>activity_id\r\n<span style=\"color: blue\">GO\r\n<\/span><\/pre>\n<\/blockquote>\n<blockquote>\n<\/blockquote>\n<blockquote>\n<p><a href=\"https:\/\/www.SQLskills.com\/blogs\/jonathan\/wp-content\/uploads\/windows-live-writer\/anxeventaday11of31targetsweekusingmulti\/610d6c3c\/image.png\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" style=\"border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px\" title=\"image\" border=\"0\" alt=\"image\" src=\"https:\/\/www.SQLskills.com\/blogs\/jonathan\/wp-content\/uploads\/windows-live-writer\/anxeventaday11of31targetsweekusingmulti\/5262c057\/image_thumb.png\" width=\"644\" height=\"47\" \/><\/a> <\/p>\n<\/blockquote>\n<p>From this we can see our orphaned transaction event, and find the attach_activity_id of that Event.&#160; The attach_activity_id Action is added to the Events in an Event Session when TRACK_CAUSALITY is turned ON.&#160; There are two pieces of information contained in the attach_activity_id Action, the activity Guid (the first 36 characters of the value) and the sequence number for the Event, the number following the Guid.&#160; The Guid can be used to find related Events, and the sequence number can be used to determine the order that the Events occurred.&#160; By using the Guid from the attach_activity_id Action from our first query, we can query the ring_buffer Target and parse out the specific Events we are interested in looking at further.<\/p>\n<blockquote>\n<pre class=\"code\"><span style=\"color: green\">-- Query the XML to get the Target Data\r\n<\/span><span style=\"color: blue\">SELECT \r\n    <\/span>n<span style=\"color: gray\">.<\/span>value<span style=\"color: gray\">(<\/span><span style=\"color: red\">'(event\/@name)[1]'<\/span><span style=\"color: gray\">, <\/span><span style=\"color: red\">'varchar(50)'<\/span><span style=\"color: gray\">) <\/span><span style=\"color: blue\">AS <\/span>event_name<span style=\"color: gray\">,\r\n    <\/span>n<span style=\"color: gray\">.<\/span>value<span style=\"color: gray\">(<\/span><span style=\"color: red\">'(event\/@package)[1]'<\/span><span style=\"color: gray\">, <\/span><span style=\"color: red\">'varchar(50)'<\/span><span style=\"color: gray\">) <\/span><span style=\"color: blue\">AS <\/span>package_name<span style=\"color: gray\">,\r\n    <\/span><span style=\"color: magenta\">DATEADD<\/span><span style=\"color: gray\">(<\/span>hh<span style=\"color: gray\">, \r\n            <\/span><span style=\"color: magenta\">DATEDIFF<\/span><span style=\"color: gray\">(<\/span>hh<span style=\"color: gray\">, <\/span><span style=\"color: magenta\">GETUTCDATE<\/span><span style=\"color: gray\">(), <\/span><span style=\"color: magenta\">CURRENT_TIMESTAMP<\/span><span style=\"color: gray\">), \r\n            <\/span>n<span style=\"color: gray\">.<\/span>value<span style=\"color: gray\">(<\/span><span style=\"color: red\">'(event\/@timestamp)[1]'<\/span><span style=\"color: gray\">, <\/span><span style=\"color: red\">'datetime2'<\/span><span style=\"color: gray\">)) <\/span><span style=\"color: blue\">AS <\/span>[timestamp]<span style=\"color: gray\">,  \r\n    <\/span>n<span style=\"color: gray\">.<\/span>value<span style=\"color: gray\">(<\/span><span style=\"color: red\">'(event\/action[@name=&quot;database_id&quot;]\/value)[1]'<\/span><span style=\"color: gray\">, <\/span><span style=\"color: red\">'int'<\/span><span style=\"color: gray\">) <\/span><span style=\"color: blue\">as <\/span>[database_id]<span style=\"color: gray\">,\r\n    <\/span>n<span style=\"color: gray\">.<\/span>value<span style=\"color: gray\">(<\/span><span style=\"color: red\">'(event\/action[@name=&quot;session_id&quot;]\/value)[1]'<\/span><span style=\"color: gray\">, <\/span><span style=\"color: red\">'int'<\/span><span style=\"color: gray\">) <\/span><span style=\"color: blue\">as <\/span>[session_id]<span style=\"color: gray\">,\r\n    <\/span>n<span style=\"color: gray\">.<\/span>value<span style=\"color: gray\">(<\/span><span style=\"color: red\">'(event\/data[@name=&quot;object_id&quot;]\/value)[1]'<\/span><span style=\"color: gray\">, <\/span><span style=\"color: red\">'int'<\/span><span style=\"color: gray\">) <\/span><span style=\"color: blue\">AS <\/span>[object_id]<span style=\"color: gray\">,\r\n    <\/span>n<span style=\"color: gray\">.<\/span>value<span style=\"color: gray\">(<\/span><span style=\"color: red\">'(event\/data[@name=&quot;object_type&quot;]\/value)[1]'<\/span><span style=\"color: gray\">, <\/span><span style=\"color: red\">'nvarchar(128)'<\/span><span style=\"color: gray\">) <\/span><span style=\"color: blue\">AS <\/span>[object_type]<span style=\"color: gray\">,\r\n    <\/span>n<span style=\"color: gray\">.<\/span>value<span style=\"color: gray\">(<\/span><span style=\"color: red\">'(event\/data[@name=&quot;object_name&quot;]\/value)[1]'<\/span><span style=\"color: gray\">, <\/span><span style=\"color: red\">'nvarchar(128)'<\/span><span style=\"color: gray\">) <\/span><span style=\"color: blue\">AS <\/span>[object_name]<span style=\"color: gray\">,\r\n    <\/span>n<span style=\"color: gray\">.<\/span>value<span style=\"color: gray\">(<\/span><span style=\"color: red\">'(event\/data[@name=&quot;error&quot;]\/value)[1]'<\/span><span style=\"color: gray\">, <\/span><span style=\"color: red\">'int'<\/span><span style=\"color: gray\">) <\/span><span style=\"color: blue\">AS <\/span>[error]<span style=\"color: gray\">,\r\n    <\/span>n<span style=\"color: gray\">.<\/span>value<span style=\"color: gray\">(<\/span><span style=\"color: red\">'(event\/data[@name=&quot;severity&quot;]\/value)[1]'<\/span><span style=\"color: gray\">, <\/span><span style=\"color: red\">'int'<\/span><span style=\"color: gray\">) <\/span><span style=\"color: blue\">AS <\/span>[severity]<span style=\"color: gray\">,\r\n    <\/span>n<span style=\"color: gray\">.<\/span>value<span style=\"color: gray\">(<\/span><span style=\"color: red\">'(event\/data[@name=&quot;state&quot;]\/value)[1]'<\/span><span style=\"color: gray\">, <\/span><span style=\"color: red\">'int'<\/span><span style=\"color: gray\">) <\/span><span style=\"color: blue\">AS <\/span>[state]<span style=\"color: gray\">,\r\n    <\/span>n<span style=\"color: gray\">.<\/span>value<span style=\"color: gray\">(<\/span><span style=\"color: red\">'(event\/data[@name=&quot;user_defined&quot;]\/value)[1]'<\/span><span style=\"color: gray\">, <\/span><span style=\"color: red\">'bit'<\/span><span style=\"color: gray\">) <\/span><span style=\"color: blue\">AS <\/span>[user_defined]<span style=\"color: gray\">,\r\n    <\/span>n<span style=\"color: gray\">.<\/span>value<span style=\"color: gray\">(<\/span><span style=\"color: red\">'(event\/data[@name=&quot;message&quot;]\/value)[1]'<\/span><span style=\"color: gray\">, <\/span><span style=\"color: red\">'nvarchar(4000)'<\/span><span style=\"color: gray\">) <\/span><span style=\"color: blue\">AS <\/span>[message]<span style=\"color: gray\">,\r\n    <\/span>n<span style=\"color: gray\">.<\/span>value<span style=\"color: gray\">(<\/span><span style=\"color: red\">'(event\/data[@name=&quot;duration&quot;]\/value)[1]'<\/span><span style=\"color: gray\">, <\/span><span style=\"color: red\">'int'<\/span><span style=\"color: gray\">) <\/span><span style=\"color: blue\">AS <\/span>[duration]<span style=\"color: gray\">,\r\n    <\/span>n<span style=\"color: gray\">.<\/span>value<span style=\"color: gray\">(<\/span><span style=\"color: red\">'(event\/data[@name=&quot;row_count&quot;]\/value)[1]'<\/span><span style=\"color: gray\">, <\/span><span style=\"color: red\">'int'<\/span><span style=\"color: gray\">) <\/span><span style=\"color: blue\">AS <\/span>[row_count]<span style=\"color: gray\">,\r\n    <\/span>n<span style=\"color: gray\">.<\/span>value<span style=\"color: gray\">(<\/span><span style=\"color: red\">'(event\/data[@name=&quot;cpu&quot;]\/value)[1]'<\/span><span style=\"color: gray\">, <\/span><span style=\"color: red\">'int'<\/span><span style=\"color: gray\">) <\/span><span style=\"color: blue\">AS <\/span>[cpu]<span style=\"color: gray\">,\r\n    <\/span>n<span style=\"color: gray\">.<\/span>value<span style=\"color: gray\">(<\/span><span style=\"color: red\">'(event\/data[@name=&quot;reads&quot;]\/value)[1]'<\/span><span style=\"color: gray\">, <\/span><span style=\"color: red\">'int'<\/span><span style=\"color: gray\">) <\/span><span style=\"color: blue\">AS <\/span>[reads]<span style=\"color: gray\">,\r\n    <\/span>n<span style=\"color: gray\">.<\/span>value<span style=\"color: gray\">(<\/span><span style=\"color: red\">'(event\/data[@name=&quot;writes&quot;]\/value)[1]'<\/span><span style=\"color: gray\">, <\/span><span style=\"color: red\">'int'<\/span><span style=\"color: gray\">) <\/span><span style=\"color: blue\">AS <\/span>[writes]<span style=\"color: gray\">,\r\n    <\/span>n<span style=\"color: gray\">.<\/span>value<span style=\"color: gray\">(<\/span><span style=\"color: red\">'(event\/action[@name=&quot;tsql_stack&quot;]\/value)[1]'<\/span><span style=\"color: gray\">, <\/span><span style=\"color: red\">'nvarchar(max)'<\/span><span style=\"color: gray\">) <\/span><span style=\"color: blue\">AS <\/span>[tsql_stack]<span style=\"color: gray\">,\r\n    <\/span>n<span style=\"color: gray\">.<\/span>value<span style=\"color: gray\">(<\/span><span style=\"color: red\">'(event\/data[@name=&quot;offset&quot;]\/value)[1]'<\/span><span style=\"color: gray\">, <\/span><span style=\"color: red\">'int'<\/span><span style=\"color: gray\">) <\/span><span style=\"color: blue\">AS <\/span>[offset]<span style=\"color: gray\">,\r\n    <\/span>n<span style=\"color: gray\">.<\/span>value<span style=\"color: gray\">(<\/span><span style=\"color: red\">'(event\/data[@name=&quot;offset_end&quot;]\/value)[1]'<\/span><span style=\"color: gray\">, <\/span><span style=\"color: red\">'int'<\/span><span style=\"color: gray\">) <\/span><span style=\"color: blue\">AS <\/span>[offset_end]<span style=\"color: gray\">,\r\n    <\/span>n<span style=\"color: gray\">.<\/span>value<span style=\"color: gray\">(<\/span><span style=\"color: red\">'(event\/data[@name=&quot;nest_level&quot;]\/value)[1]'<\/span><span style=\"color: gray\">, <\/span><span style=\"color: red\">'int'<\/span><span style=\"color: gray\">) <\/span><span style=\"color: blue\">AS <\/span>[nest_level]<span style=\"color: gray\">,           \r\n     <\/span>n<span style=\"color: gray\">.<\/span>value<span style=\"color: gray\">(<\/span><span style=\"color: red\">'(event\/action[@name=&quot;sql_text&quot;]\/value)[1]'<\/span><span style=\"color: gray\">, <\/span><span style=\"color: red\">'nvarchar(max)'<\/span><span style=\"color: gray\">) <\/span><span style=\"color: blue\">AS <\/span>[sql_text]<span style=\"color: gray\">,\r\n    <\/span><span style=\"color: magenta\">CAST<\/span><span style=\"color: gray\">(<\/span><span style=\"color: magenta\">SUBSTRING<\/span><span style=\"color: gray\">(<\/span>n<span style=\"color: gray\">.<\/span>value<span style=\"color: gray\">(<\/span><span style=\"color: red\">'(event\/action[@name=&quot;attach_activity_id&quot;]\/value)[1]'<\/span><span style=\"color: gray\">, <\/span><span style=\"color: red\">'varchar(50)'<\/span><span style=\"color: gray\">), <\/span>1<span style=\"color: gray\">, <\/span>36<span style=\"color: gray\">) <\/span><span style=\"color: blue\">AS uniqueidentifier<\/span><span style=\"color: gray\">) <\/span><span style=\"color: blue\">AS <\/span>activity_id<span style=\"color: gray\">,\r\n    <\/span><span style=\"color: magenta\">CAST<\/span><span style=\"color: gray\">(<\/span><span style=\"color: magenta\">SUBSTRING<\/span><span style=\"color: gray\">(<\/span>n<span style=\"color: gray\">.<\/span>value<span style=\"color: gray\">(<\/span><span style=\"color: red\">'(event\/action[@name=&quot;attach_activity_id&quot;]\/value)[1]'<\/span><span style=\"color: gray\">, <\/span><span style=\"color: red\">'varchar(50)'<\/span><span style=\"color: gray\">), <\/span>38<span style=\"color: gray\">, <\/span>10<span style=\"color: gray\">) <\/span><span style=\"color: blue\">AS int<\/span><span style=\"color: gray\">) <\/span><span style=\"color: blue\">AS <\/span>event_sequence\r\n<span style=\"color: blue\">FROM\r\n<\/span><span style=\"color: gray\">(    <\/span><span style=\"color: blue\">SELECT <\/span>td<span style=\"color: gray\">.<\/span>query<span style=\"color: gray\">(<\/span><span style=\"color: red\">'.'<\/span><span style=\"color: gray\">) <\/span><span style=\"color: blue\">as <\/span>n\r\n    <span style=\"color: blue\">FROM \r\n    <\/span><span style=\"color: gray\">(\r\n        <\/span><span style=\"color: blue\">SELECT <\/span><span style=\"color: magenta\">CAST<\/span><span style=\"color: gray\">(<\/span>target_data <span style=\"color: blue\">AS XML<\/span><span style=\"color: gray\">) <\/span><span style=\"color: blue\">as <\/span>target_data\r\n        <span style=\"color: blue\">FROM <\/span><span style=\"color: green\">sys<\/span><span style=\"color: gray\">.<\/span><span style=\"color: green\">dm_xe_sessions <\/span><span style=\"color: blue\">AS <\/span>s \r\n        <span style=\"color: gray\">JOIN <\/span><span style=\"color: green\">sys<\/span><span style=\"color: gray\">.<\/span><span style=\"color: green\">dm_xe_session_targets <\/span><span style=\"color: blue\">AS <\/span>t \r\n            <span style=\"color: blue\">ON <\/span>t<span style=\"color: gray\">.<\/span>event_session_address <span style=\"color: gray\">= <\/span>s<span style=\"color: gray\">.<\/span><span style=\"color: blue\">address\r\n        WHERE <\/span>s<span style=\"color: gray\">.<\/span>name <span style=\"color: gray\">= <\/span><span style=\"color: red\">'OrphanedTransactionHunter'\r\n          <\/span><span style=\"color: gray\">AND <\/span>t<span style=\"color: gray\">.<\/span>target_name <span style=\"color: gray\">= <\/span><span style=\"color: red\">'ring_buffer'\r\n    <\/span><span style=\"color: gray\">) <\/span><span style=\"color: blue\">AS <\/span>sub\r\n    <span style=\"color: gray\">CROSS APPLY <\/span>target_data<span style=\"color: gray\">.<\/span>nodes<span style=\"color: gray\">(<\/span><span style=\"color: red\">'RingBufferTarget\/event'<\/span><span style=\"color: gray\">) <\/span><span style=\"color: blue\">AS <\/span>q<span style=\"color: gray\">(<\/span>td<span style=\"color: gray\">)\r\n) <\/span><span style=\"color: blue\">as <\/span>tab\r\n<span style=\"color: green\">-- We are interested in unmatched sqlserver.database_transaction_begin Events\r\n<\/span><span style=\"color: blue\">WHERE <\/span><span style=\"color: magenta\">SUBSTRING<\/span><span style=\"color: gray\">(<\/span>n<span style=\"color: gray\">.<\/span>value<span style=\"color: gray\">(<\/span><span style=\"color: red\">'(event\/action[@name=&quot;attach_activity_id&quot;]\/value)[1]'<\/span><span style=\"color: gray\">, <\/span><span style=\"color: red\">'varchar(50)'<\/span><span style=\"color: gray\">), <\/span>1<span style=\"color: gray\">, <\/span>36<span style=\"color: gray\">) = <\/span><span style=\"color: red\">'ADCF379A-4BCA-41BA-9B08-4C2265894392'\r\n<\/span><span style=\"color: blue\">ORDER BY <\/span>session_id<span style=\"color: gray\">, <\/span>event_sequence\r\n<span style=\"color: blue\">GO\r\n<\/span><\/pre>\n<\/blockquote>\n<p>&#160;<\/p>\n<p>With a little bit more work, we can reduce the XML parsing to only the important data elements that we need, and we can parse the tsql_stack Action to retrieve the related Event level statement_text from the sys.dm_exec_sql_text() DMF, since the sql_text Action did not have the intended information. <\/p>\n<blockquote>\n<pre class=\"code\"><span style=\"color: green\">-- Query the XML to get the Target Data\r\n<\/span><span style=\"color: blue\">SELECT \r\n    <\/span>event_name<span style=\"color: gray\">,\r\n    <\/span><span style=\"color: blue\">timestamp<\/span><span style=\"color: gray\">,\r\n    <\/span>database_id<span style=\"color: gray\">, \r\n    <\/span><span style=\"color: magenta\">OBJECT_NAME<\/span><span style=\"color: gray\">(<\/span>st<span style=\"color: gray\">.<\/span>objectid<span style=\"color: gray\">, <\/span>st<span style=\"color: gray\">.<\/span><span style=\"color: blue\">dbid<\/span><span style=\"color: gray\">) <\/span><span style=\"color: blue\">AS <\/span>ObjectName<span style=\"color: gray\">,\r\n    <\/span><span style=\"color: magenta\">SUBSTRING<\/span><span style=\"color: gray\">(<\/span>st<span style=\"color: gray\">.<\/span><span style=\"color: blue\">text<\/span><span style=\"color: gray\">, (<\/span>tsql_stack<span style=\"color: gray\">.<\/span>value<span style=\"color: gray\">(<\/span><span style=\"color: red\">'(\/frame\/@offsetStart)[1]'<\/span><span style=\"color: gray\">, <\/span><span style=\"color: red\">'int'<\/span><span style=\"color: gray\">)\/<\/span>2<span style=\"color: gray\">)+<\/span>1<span style=\"color: gray\">, \r\n        ((<\/span><span style=\"color: blue\">CASE <\/span>tsql_stack<span style=\"color: gray\">.<\/span>value<span style=\"color: gray\">(<\/span><span style=\"color: red\">'(\/frame\/@offsetEnd)[1]'<\/span><span style=\"color: gray\">, <\/span><span style=\"color: red\">'int'<\/span><span style=\"color: gray\">)\r\n            <\/span><span style=\"color: blue\">WHEN <\/span><span style=\"color: gray\">-<\/span>1 <span style=\"color: blue\">THEN <\/span><span style=\"color: magenta\">DATALENGTH<\/span><span style=\"color: gray\">(<\/span>st<span style=\"color: gray\">.<\/span><span style=\"color: blue\">text<\/span><span style=\"color: gray\">)\r\n            <\/span><span style=\"color: blue\">ELSE <\/span>tsql_stack<span style=\"color: gray\">.<\/span>value<span style=\"color: gray\">(<\/span><span style=\"color: red\">'(\/frame\/@offsetEnd)[1]'<\/span><span style=\"color: gray\">, <\/span><span style=\"color: red\">'int'<\/span><span style=\"color: gray\">)\r\n            <\/span><span style=\"color: blue\">END <\/span><span style=\"color: gray\">- <\/span>tsql_stack<span style=\"color: gray\">.<\/span>value<span style=\"color: gray\">(<\/span><span style=\"color: red\">'(\/frame\/@offsetStart)[1]'<\/span><span style=\"color: gray\">, <\/span><span style=\"color: red\">'int'<\/span><span style=\"color: gray\">))\/<\/span>2<span style=\"color: gray\">) + <\/span>1<span style=\"color: gray\">) <\/span><span style=\"color: blue\">AS <\/span>statement_text<span style=\"color: gray\">,\r\n    <\/span>duration<span style=\"color: gray\">,\r\n    <\/span>activity_id<span style=\"color: gray\">,\r\n    <\/span>event_sequence\r\n<span style=\"color: blue\">FROM\r\n<\/span><span style=\"color: gray\">(\r\n<\/span><span style=\"color: blue\">SELECT \r\n    <\/span>n<span style=\"color: gray\">.<\/span>value<span style=\"color: gray\">(<\/span><span style=\"color: red\">'(event\/@name)[1]'<\/span><span style=\"color: gray\">, <\/span><span style=\"color: red\">'varchar(50)'<\/span><span style=\"color: gray\">) <\/span><span style=\"color: blue\">AS <\/span>event_name<span style=\"color: gray\">,\r\n<\/span><span style=\"color: gray\">    <\/span><span style=\"color: magenta\">DATEADD<\/span><span style=\"color: gray\">(<\/span>hh<span style=\"color: gray\">, \r\n            <\/span><span style=\"color: magenta\">DATEDIFF<\/span><span style=\"color: gray\">(<\/span>hh<span style=\"color: gray\">, <\/span><span style=\"color: magenta\">GETUTCDATE<\/span><span style=\"color: gray\">(), <\/span><span style=\"color: magenta\">CURRENT_TIMESTAMP<\/span><span style=\"color: gray\">), \r\n            <\/span>n<span style=\"color: gray\">.<\/span>value<span style=\"color: gray\">(<\/span><span style=\"color: red\">'(event\/@timestamp)[1]'<\/span><span style=\"color: gray\">, <\/span><span style=\"color: red\">'datetime2'<\/span><span style=\"color: gray\">)) <\/span><span style=\"color: blue\">AS <\/span>[timestamp]<span style=\"color: gray\">,  \r\n    <\/span>n<span style=\"color: gray\">.<\/span>value<span style=\"color: gray\">(<\/span><span style=\"color: red\">'(event\/action[@name=&quot;database_id&quot;]\/value)[1]'<\/span><span style=\"color: gray\">, <\/span><span style=\"color: red\">'int'<\/span><span style=\"color: gray\">) <\/span><span style=\"color: blue\">as <\/span>[database_id]<span style=\"color: gray\">,\r\n<\/span><span style=\"color: gray\">    <\/span>n<span style=\"color: gray\">.<\/span>value<span style=\"color: gray\">(<\/span><span style=\"color: red\">'(event\/data[@name=&quot;duration&quot;]\/value)[1]'<\/span><span style=\"color: gray\">, <\/span><span style=\"color: red\">'int'<\/span><span style=\"color: gray\">) <\/span><span style=\"color: blue\">AS <\/span>[duration]<span style=\"color: gray\">,\r\n<\/span><span style=\"color: gray\">    <\/span><span style=\"color: magenta\">CAST<\/span><span style=\"color: gray\">(<\/span>n<span style=\"color: gray\">.<\/span>value<span style=\"color: gray\">(<\/span><span style=\"color: red\">'(event\/action[@name=&quot;tsql_stack&quot;]\/value)[1]'<\/span><span style=\"color: gray\">, <\/span><span style=\"color: red\">'nvarchar(max)'<\/span><span style=\"color: gray\">) <\/span><span style=\"color: blue\">AS XML<\/span><span style=\"color: gray\">) <\/span><span style=\"color: blue\">AS <\/span>[tsql_stack]<span style=\"color: gray\">,\r\n<\/span><span style=\"color: gray\">    <\/span><span style=\"color: magenta\">CAST<\/span><span style=\"color: gray\">(<\/span><span style=\"color: magenta\">SUBSTRING<\/span><span style=\"color: gray\">(<\/span>n<span style=\"color: gray\">.<\/span>value<span style=\"color: gray\">(<\/span><span style=\"color: red\">'(event\/action[@name=&quot;attach_activity_id&quot;]\/value)[1]'<\/span><span style=\"color: gray\">, <\/span><span style=\"color: red\">'varchar(50)'<\/span><span style=\"color: gray\">), <\/span>1<span style=\"color: gray\">, <\/span>36<span style=\"color: gray\">) <\/span><span style=\"color: blue\">AS uniqueidentifier<\/span><span style=\"color: gray\">) <\/span><span style=\"color: blue\">AS <\/span>activity_id<span style=\"color: gray\">,\r\n    <\/span><span style=\"color: magenta\">CAST<\/span><span style=\"color: gray\">(<\/span><span style=\"color: magenta\">SUBSTRING<\/span><span style=\"color: gray\">(<\/span>n<span style=\"color: gray\">.<\/span>value<span style=\"color: gray\">(<\/span><span style=\"color: red\">'(event\/action[@name=&quot;attach_activity_id&quot;]\/value)[1]'<\/span><span style=\"color: gray\">, <\/span><span style=\"color: red\">'varchar(50)'<\/span><span style=\"color: gray\">), <\/span>38<span style=\"color: gray\">, <\/span>10<span style=\"color: gray\">) <\/span><span style=\"color: blue\">AS int<\/span><span style=\"color: gray\">) <\/span><span style=\"color: blue\">AS <\/span>event_sequence\r\n<span style=\"color: blue\">FROM\r\n<\/span><span style=\"color: gray\">(    <\/span><span style=\"color: blue\">SELECT <\/span>td<span style=\"color: gray\">.<\/span>query<span style=\"color: gray\">(<\/span><span style=\"color: red\">'.'<\/span><span style=\"color: gray\">) <\/span><span style=\"color: blue\">as <\/span>n\r\n    <span style=\"color: blue\">FROM \r\n    <\/span><span style=\"color: gray\">(\r\n        <\/span><span style=\"color: blue\">SELECT <\/span><span style=\"color: magenta\">CAST<\/span><span style=\"color: gray\">(<\/span>target_data <span style=\"color: blue\">AS XML<\/span><span style=\"color: gray\">) <\/span><span style=\"color: blue\">as <\/span>target_data\r\n        <span style=\"color: blue\">FROM <\/span><span style=\"color: green\">sys<\/span><span style=\"color: gray\">.<\/span><span style=\"color: green\">dm_xe_sessions <\/span><span style=\"color: blue\">AS <\/span>s \r\n        <span style=\"color: gray\">JOIN <\/span><span style=\"color: green\">sys<\/span><span style=\"color: gray\">.<\/span><span style=\"color: green\">dm_xe_session_targets <\/span><span style=\"color: blue\">AS <\/span>t \r\n            <span style=\"color: blue\">ON <\/span>t<span style=\"color: gray\">.<\/span>event_session_address <span style=\"color: gray\">= <\/span>s<span style=\"color: gray\">.<\/span><span style=\"color: blue\">address\r\n        WHERE <\/span>s<span style=\"color: gray\">.<\/span>name <span style=\"color: gray\">= <\/span><span style=\"color: red\">'OrphanedTransactionHunter'\r\n          <\/span><span style=\"color: gray\">AND <\/span>t<span style=\"color: gray\">.<\/span>target_name <span style=\"color: gray\">= <\/span><span style=\"color: red\">'ring_buffer'\r\n    <\/span><span style=\"color: gray\">) <\/span><span style=\"color: blue\">AS <\/span>sub\r\n    <span style=\"color: gray\">CROSS APPLY <\/span>target_data<span style=\"color: gray\">.<\/span>nodes<span style=\"color: gray\">(<\/span><span style=\"color: red\">'RingBufferTarget\/event'<\/span><span style=\"color: gray\">) <\/span><span style=\"color: blue\">AS <\/span>q<span style=\"color: gray\">(<\/span>td<span style=\"color: gray\">)\r\n) <\/span><span style=\"color: blue\">as <\/span>tab\r\n<span style=\"color: gray\">) <\/span><span style=\"color: blue\">as <\/span>tab2\r\n<span style=\"color: gray\">CROSS APPLY <\/span><span style=\"color: green\">sys<\/span><span style=\"color: gray\">.<\/span><span style=\"color: green\">dm_exec_sql_text<\/span><span style=\"color: gray\">(<\/span>tsql_stack<span style=\"color: gray\">.<\/span>value<span style=\"color: gray\">(<\/span><span style=\"color: red\">'xs:hexBinary(substring((\/frame\/@handle)[1], 3))'<\/span><span style=\"color: gray\">, <\/span><span style=\"color: red\">'varbinary(max)'<\/span><span style=\"color: gray\">)) <\/span><span style=\"color: blue\">AS <\/span>st\r\n<span style=\"color: green\">-- We are interested in Events in activity_id sequence of the orphaned transaction only\r\n<\/span><span style=\"color: blue\">WHERE <\/span>activity_id <span style=\"color: gray\">= <\/span><span style=\"color: red\">'ADCF379A-4BCA-41BA-9B08-4C2265894392'\r\n<\/span><span style=\"color: blue\">ORDER BY <\/span>session_id<span style=\"color: gray\">, <\/span>event_sequence\r\n<span style=\"color: blue\">GO\r\n<\/span><\/pre>\n<\/blockquote>\n<blockquote>\n<p><a href=\"https:\/\/www.SQLskills.com\/blogs\/jonathan\/wp-content\/uploads\/windows-live-writer\/anxeventaday11of31targetsweekusingmulti\/68692be9\/image.png\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" style=\"border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px\" title=\"image\" border=\"0\" alt=\"image\" src=\"https:\/\/www.SQLskills.com\/blogs\/jonathan\/wp-content\/uploads\/windows-live-writer\/anxeventaday11of31targetsweekusingmulti\/23505eb3\/image_thumb.png\" width=\"644\" height=\"120\" \/><\/a> <\/p>\n<\/blockquote>\n<p>The highlighted value shows that the stored procedure execution ended at the Execution Timeout limit that was set for the PoorApp SSMS Instance.&#160; Beyond that we can track each of the statements and see that when the execution ended, it was in the INSERT INTO RandomObjectsArchive statement in the stored procedure allowing us to target our efforts at troubleshooting to the specific problem in a short amount of time.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Yesterday\u2019s blog post Targets Week \u2013 etw_classic_sync_target covered the ETW integration that is built into Extended Events and how the etw_classic_sync_target can be used in conjunction with other ETW traces to provide troubleshooting at a level previously not possible with SQL Server.&#160; In today\u2019s post we\u2019ll look at how to use multiple targets to simplify [&hellip;]<\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23,38,40,45],"tags":[],"class_list":["post-553","post","type-post","status-publish","format-standard","hentry","category-extended-events","category-sql-server-2008","category-sql-server-denali","category-xevent-a-day-series"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>An XEvent a Day (11 of 31) \u2013 Targets Week \u2013 Using Multiple Targets to Debug Orphaned Transactions - Jonathan Kehayias<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.sqlskills.com\/blogs\/jonathan\/an-xevent-a-day-11-of-31-targets-week-using-multiple-targets-to-debug-orphaned-transactions\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"An XEvent a Day (11 of 31) \u2013 Targets Week \u2013 Using Multiple Targets to Debug Orphaned Transactions - Jonathan Kehayias\" \/>\n<meta property=\"og:description\" content=\"Yesterday\u2019s blog post Targets Week \u2013 etw_classic_sync_target covered the ETW integration that is built into Extended Events and how the etw_classic_sync_target can be used in conjunction with other ETW traces to provide troubleshooting at a level previously not possible with SQL Server.&#160; In today\u2019s post we\u2019ll look at how to use multiple targets to simplify [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.sqlskills.com\/blogs\/jonathan\/an-xevent-a-day-11-of-31-targets-week-using-multiple-targets-to-debug-orphaned-transactions\/\" \/>\n<meta property=\"og:site_name\" content=\"Jonathan Kehayias\" \/>\n<meta property=\"article:published_time\" content=\"2010-12-11T22:46:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2017-04-13T16:17:39+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.SQLskills.com\/blogs\/jonathan\/wp-content\/uploads\/windows-live-writer\/anxeventaday11of31targetsweekusingmulti\/53b77f03\/image_thumb.png\" \/>\n<meta name=\"author\" content=\"Jonathan Kehayias\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Jonathan Kehayias\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"17 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.sqlskills.com\\\/blogs\\\/jonathan\\\/an-xevent-a-day-11-of-31-targets-week-using-multiple-targets-to-debug-orphaned-transactions\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.sqlskills.com\\\/blogs\\\/jonathan\\\/an-xevent-a-day-11-of-31-targets-week-using-multiple-targets-to-debug-orphaned-transactions\\\/\"},\"author\":{\"name\":\"Jonathan Kehayias\",\"@id\":\"https:\\\/\\\/www.sqlskills.com\\\/blogs\\\/jonathan\\\/#\\\/schema\\\/person\\\/01c10d94f3648654ef706d5e6305f69c\"},\"headline\":\"An XEvent a Day (11 of 31) \u2013 Targets Week \u2013 Using Multiple Targets to Debug Orphaned Transactions\",\"datePublished\":\"2010-12-11T22:46:00+00:00\",\"dateModified\":\"2017-04-13T16:17:39+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.sqlskills.com\\\/blogs\\\/jonathan\\\/an-xevent-a-day-11-of-31-targets-week-using-multiple-targets-to-debug-orphaned-transactions\\\/\"},\"wordCount\":1812,\"commentCount\":3,\"image\":{\"@id\":\"https:\\\/\\\/www.sqlskills.com\\\/blogs\\\/jonathan\\\/an-xevent-a-day-11-of-31-targets-week-using-multiple-targets-to-debug-orphaned-transactions\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.SQLskills.com\\\/blogs\\\/jonathan\\\/wp-content\\\/uploads\\\/windows-live-writer\\\/anxeventaday11of31targetsweekusingmulti\\\/53b77f03\\\/image_thumb.png\",\"articleSection\":[\"Extended Events\",\"SQL Server 2008\",\"SQL Server Denali\",\"XEvent a Day Series\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.sqlskills.com\\\/blogs\\\/jonathan\\\/an-xevent-a-day-11-of-31-targets-week-using-multiple-targets-to-debug-orphaned-transactions\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.sqlskills.com\\\/blogs\\\/jonathan\\\/an-xevent-a-day-11-of-31-targets-week-using-multiple-targets-to-debug-orphaned-transactions\\\/\",\"url\":\"https:\\\/\\\/www.sqlskills.com\\\/blogs\\\/jonathan\\\/an-xevent-a-day-11-of-31-targets-week-using-multiple-targets-to-debug-orphaned-transactions\\\/\",\"name\":\"An XEvent a Day (11 of 31) \u2013 Targets Week \u2013 Using Multiple Targets to Debug Orphaned Transactions - Jonathan Kehayias\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.sqlskills.com\\\/blogs\\\/jonathan\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.sqlskills.com\\\/blogs\\\/jonathan\\\/an-xevent-a-day-11-of-31-targets-week-using-multiple-targets-to-debug-orphaned-transactions\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.sqlskills.com\\\/blogs\\\/jonathan\\\/an-xevent-a-day-11-of-31-targets-week-using-multiple-targets-to-debug-orphaned-transactions\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.SQLskills.com\\\/blogs\\\/jonathan\\\/wp-content\\\/uploads\\\/windows-live-writer\\\/anxeventaday11of31targetsweekusingmulti\\\/53b77f03\\\/image_thumb.png\",\"datePublished\":\"2010-12-11T22:46:00+00:00\",\"dateModified\":\"2017-04-13T16:17:39+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.sqlskills.com\\\/blogs\\\/jonathan\\\/#\\\/schema\\\/person\\\/01c10d94f3648654ef706d5e6305f69c\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.sqlskills.com\\\/blogs\\\/jonathan\\\/an-xevent-a-day-11-of-31-targets-week-using-multiple-targets-to-debug-orphaned-transactions\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.sqlskills.com\\\/blogs\\\/jonathan\\\/an-xevent-a-day-11-of-31-targets-week-using-multiple-targets-to-debug-orphaned-transactions\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.sqlskills.com\\\/blogs\\\/jonathan\\\/an-xevent-a-day-11-of-31-targets-week-using-multiple-targets-to-debug-orphaned-transactions\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.SQLskills.com\\\/blogs\\\/jonathan\\\/wp-content\\\/uploads\\\/windows-live-writer\\\/anxeventaday11of31targetsweekusingmulti\\\/53b77f03\\\/image_thumb.png\",\"contentUrl\":\"https:\\\/\\\/www.SQLskills.com\\\/blogs\\\/jonathan\\\/wp-content\\\/uploads\\\/windows-live-writer\\\/anxeventaday11of31targetsweekusingmulti\\\/53b77f03\\\/image_thumb.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.sqlskills.com\\\/blogs\\\/jonathan\\\/an-xevent-a-day-11-of-31-targets-week-using-multiple-targets-to-debug-orphaned-transactions\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.sqlskills.com\\\/blogs\\\/jonathan\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Extended Events\",\"item\":\"https:\\\/\\\/www.sqlskills.com\\\/blogs\\\/jonathan\\\/category\\\/extended-events\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"An XEvent a Day (11 of 31) \u2013 Targets Week \u2013 Using Multiple Targets to Debug Orphaned Transactions\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.sqlskills.com\\\/blogs\\\/jonathan\\\/#website\",\"url\":\"https:\\\/\\\/www.sqlskills.com\\\/blogs\\\/jonathan\\\/\",\"name\":\"Jonathan Kehayias - The Rambling DBA\",\"description\":\"The Rambling DBA\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.sqlskills.com\\\/blogs\\\/jonathan\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.sqlskills.com\\\/blogs\\\/jonathan\\\/#\\\/schema\\\/person\\\/01c10d94f3648654ef706d5e6305f69c\",\"name\":\"Jonathan Kehayias\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/86630e27f5deecc5c393ea57fc7c3b6a068949f4fd6b5309f81de5a276f12855?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/86630e27f5deecc5c393ea57fc7c3b6a068949f4fd6b5309f81de5a276f12855?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/86630e27f5deecc5c393ea57fc7c3b6a068949f4fd6b5309f81de5a276f12855?s=96&d=mm&r=g\",\"caption\":\"Jonathan Kehayias\"},\"sameAs\":[\"http:\\\/\\\/3.209.169.194\\\/blogs\\\/jonathan\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"An XEvent a Day (11 of 31) \u2013 Targets Week \u2013 Using Multiple Targets to Debug Orphaned Transactions - Jonathan Kehayias","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.sqlskills.com\/blogs\/jonathan\/an-xevent-a-day-11-of-31-targets-week-using-multiple-targets-to-debug-orphaned-transactions\/","og_locale":"en_US","og_type":"article","og_title":"An XEvent a Day (11 of 31) \u2013 Targets Week \u2013 Using Multiple Targets to Debug Orphaned Transactions - Jonathan Kehayias","og_description":"Yesterday\u2019s blog post Targets Week \u2013 etw_classic_sync_target covered the ETW integration that is built into Extended Events and how the etw_classic_sync_target can be used in conjunction with other ETW traces to provide troubleshooting at a level previously not possible with SQL Server.&#160; In today\u2019s post we\u2019ll look at how to use multiple targets to simplify [&hellip;]","og_url":"https:\/\/www.sqlskills.com\/blogs\/jonathan\/an-xevent-a-day-11-of-31-targets-week-using-multiple-targets-to-debug-orphaned-transactions\/","og_site_name":"Jonathan Kehayias","article_published_time":"2010-12-11T22:46:00+00:00","article_modified_time":"2017-04-13T16:17:39+00:00","og_image":[{"url":"https:\/\/www.SQLskills.com\/blogs\/jonathan\/wp-content\/uploads\/windows-live-writer\/anxeventaday11of31targetsweekusingmulti\/53b77f03\/image_thumb.png","type":"","width":"","height":""}],"author":"Jonathan Kehayias","twitter_misc":{"Written by":"Jonathan Kehayias","Est. reading time":"17 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.sqlskills.com\/blogs\/jonathan\/an-xevent-a-day-11-of-31-targets-week-using-multiple-targets-to-debug-orphaned-transactions\/#article","isPartOf":{"@id":"https:\/\/www.sqlskills.com\/blogs\/jonathan\/an-xevent-a-day-11-of-31-targets-week-using-multiple-targets-to-debug-orphaned-transactions\/"},"author":{"name":"Jonathan Kehayias","@id":"https:\/\/www.sqlskills.com\/blogs\/jonathan\/#\/schema\/person\/01c10d94f3648654ef706d5e6305f69c"},"headline":"An XEvent a Day (11 of 31) \u2013 Targets Week \u2013 Using Multiple Targets to Debug Orphaned Transactions","datePublished":"2010-12-11T22:46:00+00:00","dateModified":"2017-04-13T16:17:39+00:00","mainEntityOfPage":{"@id":"https:\/\/www.sqlskills.com\/blogs\/jonathan\/an-xevent-a-day-11-of-31-targets-week-using-multiple-targets-to-debug-orphaned-transactions\/"},"wordCount":1812,"commentCount":3,"image":{"@id":"https:\/\/www.sqlskills.com\/blogs\/jonathan\/an-xevent-a-day-11-of-31-targets-week-using-multiple-targets-to-debug-orphaned-transactions\/#primaryimage"},"thumbnailUrl":"https:\/\/www.SQLskills.com\/blogs\/jonathan\/wp-content\/uploads\/windows-live-writer\/anxeventaday11of31targetsweekusingmulti\/53b77f03\/image_thumb.png","articleSection":["Extended Events","SQL Server 2008","SQL Server Denali","XEvent a Day Series"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.sqlskills.com\/blogs\/jonathan\/an-xevent-a-day-11-of-31-targets-week-using-multiple-targets-to-debug-orphaned-transactions\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.sqlskills.com\/blogs\/jonathan\/an-xevent-a-day-11-of-31-targets-week-using-multiple-targets-to-debug-orphaned-transactions\/","url":"https:\/\/www.sqlskills.com\/blogs\/jonathan\/an-xevent-a-day-11-of-31-targets-week-using-multiple-targets-to-debug-orphaned-transactions\/","name":"An XEvent a Day (11 of 31) \u2013 Targets Week \u2013 Using Multiple Targets to Debug Orphaned Transactions - Jonathan Kehayias","isPartOf":{"@id":"https:\/\/www.sqlskills.com\/blogs\/jonathan\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.sqlskills.com\/blogs\/jonathan\/an-xevent-a-day-11-of-31-targets-week-using-multiple-targets-to-debug-orphaned-transactions\/#primaryimage"},"image":{"@id":"https:\/\/www.sqlskills.com\/blogs\/jonathan\/an-xevent-a-day-11-of-31-targets-week-using-multiple-targets-to-debug-orphaned-transactions\/#primaryimage"},"thumbnailUrl":"https:\/\/www.SQLskills.com\/blogs\/jonathan\/wp-content\/uploads\/windows-live-writer\/anxeventaday11of31targetsweekusingmulti\/53b77f03\/image_thumb.png","datePublished":"2010-12-11T22:46:00+00:00","dateModified":"2017-04-13T16:17:39+00:00","author":{"@id":"https:\/\/www.sqlskills.com\/blogs\/jonathan\/#\/schema\/person\/01c10d94f3648654ef706d5e6305f69c"},"breadcrumb":{"@id":"https:\/\/www.sqlskills.com\/blogs\/jonathan\/an-xevent-a-day-11-of-31-targets-week-using-multiple-targets-to-debug-orphaned-transactions\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.sqlskills.com\/blogs\/jonathan\/an-xevent-a-day-11-of-31-targets-week-using-multiple-targets-to-debug-orphaned-transactions\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.sqlskills.com\/blogs\/jonathan\/an-xevent-a-day-11-of-31-targets-week-using-multiple-targets-to-debug-orphaned-transactions\/#primaryimage","url":"https:\/\/www.SQLskills.com\/blogs\/jonathan\/wp-content\/uploads\/windows-live-writer\/anxeventaday11of31targetsweekusingmulti\/53b77f03\/image_thumb.png","contentUrl":"https:\/\/www.SQLskills.com\/blogs\/jonathan\/wp-content\/uploads\/windows-live-writer\/anxeventaday11of31targetsweekusingmulti\/53b77f03\/image_thumb.png"},{"@type":"BreadcrumbList","@id":"https:\/\/www.sqlskills.com\/blogs\/jonathan\/an-xevent-a-day-11-of-31-targets-week-using-multiple-targets-to-debug-orphaned-transactions\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.sqlskills.com\/blogs\/jonathan\/"},{"@type":"ListItem","position":2,"name":"Extended Events","item":"https:\/\/www.sqlskills.com\/blogs\/jonathan\/category\/extended-events\/"},{"@type":"ListItem","position":3,"name":"An XEvent a Day (11 of 31) \u2013 Targets Week \u2013 Using Multiple Targets to Debug Orphaned Transactions"}]},{"@type":"WebSite","@id":"https:\/\/www.sqlskills.com\/blogs\/jonathan\/#website","url":"https:\/\/www.sqlskills.com\/blogs\/jonathan\/","name":"Jonathan Kehayias - The Rambling DBA","description":"The Rambling DBA","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.sqlskills.com\/blogs\/jonathan\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.sqlskills.com\/blogs\/jonathan\/#\/schema\/person\/01c10d94f3648654ef706d5e6305f69c","name":"Jonathan Kehayias","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/86630e27f5deecc5c393ea57fc7c3b6a068949f4fd6b5309f81de5a276f12855?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/86630e27f5deecc5c393ea57fc7c3b6a068949f4fd6b5309f81de5a276f12855?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/86630e27f5deecc5c393ea57fc7c3b6a068949f4fd6b5309f81de5a276f12855?s=96&d=mm&r=g","caption":"Jonathan Kehayias"},"sameAs":["http:\/\/3.209.169.194\/blogs\/jonathan"]}]}},"_links":{"self":[{"href":"https:\/\/www.sqlskills.com\/blogs\/jonathan\/wp-json\/wp\/v2\/posts\/553","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.sqlskills.com\/blogs\/jonathan\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sqlskills.com\/blogs\/jonathan\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/jonathan\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/jonathan\/wp-json\/wp\/v2\/comments?post=553"}],"version-history":[{"count":0,"href":"https:\/\/www.sqlskills.com\/blogs\/jonathan\/wp-json\/wp\/v2\/posts\/553\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.sqlskills.com\/blogs\/jonathan\/wp-json\/wp\/v2\/media?parent=553"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/jonathan\/wp-json\/wp\/v2\/categories?post=553"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/jonathan\/wp-json\/wp\/v2\/tags?post=553"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}