{"id":1514,"date":"2017-12-10T01:59:42","date_gmt":"2017-12-10T01:59:42","guid":{"rendered":"http:\/\/www.theSQLReport.com\/?p=1514"},"modified":"2017-12-10T13:52:59","modified_gmt":"2017-12-10T13:52:59","slug":"trace-flag-for-troubleshooting-lost-or-dropped-connections-in-sql-server","status":"publish","type":"post","link":"http:\/\/www.theSQLReport.com\/?p=1514","title":{"rendered":"Trace Flag for Troubleshooting Lost or Dropped Connections in SQL Server"},"content":{"rendered":"<p><strong>Problem:<\/strong> About once a month, I get support ticket regarding SQL Server dropping an application&#8217;s or user&#8217;s connection.\u00a0 The problem is SQL Server does not just randomly drop a connection and continue to work normally.\u00a0 Some force outside the control of SQL Server breaks the connection.\u00a0 By default, SQL Server does not record when this event occurs.<\/p>\n<p>In my history of working with SQL Server, only in extreme situations have I ever seen SQL Server drop its connections.\u00a0 The most common example is when SQL Server is in the process of shutting down.<\/p>\n<p><strong>Troubleshooting:<\/strong> Trace flag\u00a04029 can help in trouble shooting this issue. Information about the date, time, and SPID, along with how SQL Server sees this event happening is recorded to its error log.<\/p>\n<p>Please note that I have not found anything about this trace flag in MSDN or Technet, so this is probably an undocumented trace flag.<\/p>\n<p>In Yusuf Anis&#8217;s article &#8220;<a href=\"http:\/\/www.sqlservercentral.com\/articles\/trace+flags\/70131\/\" target=\"_blank\">SQL Server Trace Flags<\/a>&#8221; on the SQL Server Central website<br \/>\ndescribes the trace flag 4029:\u00a0 &#8220;Logs extended errors to errorlog when network disconnect occurs, turned off by default. Will dump out the socket error code this can sometimes give you a clue as to the root cause.&#8221;<\/p>\n<p>In many posts on this trace flag is paired with trace flag 3689.\u00a0\u00a0 In my testing, this trace flag is only necessary with versions of SQL Server 2000 or earlier.\u00a0 This trace flag enabled the error to be written to the error log.\u00a0 With versions SQL Server 2005 &amp; later, this trace is not required with 4029, but does no harm if enabled.<\/p>\n<p>To enable trace flag, use the &#8220;DBCC TRACEON&#8221; command with the additional &#8220;-1&#8221; trace flag to sets this as a global trace flag for all connections.\u00a0 This trace flag will remain active until turned off or SQL Server is restarted.<\/p>\n<pre>DBCC TRACEON(4029,-1);\r\nGO<\/pre>\n<p><a href=\"http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2017\/12\/TraceOn4029.jpg\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-1519 size-full\" src=\"http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2017\/12\/TraceOn4029.jpg\" alt=\"DBCC TRACEON 4029\" width=\"977\" height=\"208\" srcset=\"http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2017\/12\/TraceOn4029.jpg 977w, http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2017\/12\/TraceOn4029-300x64.jpg 300w, http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2017\/12\/TraceOn4029-768x164.jpg 768w, http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2017\/12\/TraceOn4029-210x45.jpg 210w, http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2017\/12\/TraceOn4029-976x208.jpg 976w\" sizes=\"(max-width: 977px) 100vw, 977px\" \/><\/a><\/p>\n<p>Verify that the trace flag&#8217;s status by running DBCC TRACESTATUS,<\/p>\n<pre>DBCC TRACESTATUS;\r\nGO<\/pre>\n<p><a href=\"http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2017\/12\/Verify4029.jpg\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-1521 size-full\" src=\"http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2017\/12\/Verify4029.jpg\" alt=\"Verify Trace Flag 4029\" width=\"494\" height=\"212\" \/><\/a><\/p>\n<p>Also the trace flag can be set when SQL Server starts\u00a0by adding the &#8220;-T4029&#8221; in the Startup Parameters of the instance properties in the SQL Server Configuration Manager.<\/p>\n<p><a href=\"http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2017\/12\/StartupParameter4029.jpg\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-1520 size-full\" src=\"http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2017\/12\/StartupParameter4029.jpg\" alt=\"Startup Parameter -T4029\" width=\"428\" height=\"501\" srcset=\"http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2017\/12\/StartupParameter4029.jpg 428w, http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2017\/12\/StartupParameter4029-256x300.jpg 256w, http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2017\/12\/StartupParameter4029-179x210.jpg 179w\" sizes=\"(max-width: 428px) 100vw, 428px\" \/><\/a><\/p>\n<p><strong>When a lost or dropped connection event occurs:<\/strong><\/p>\n<p>In my example I killed the SQL Server Studio Manager process in the task manager while running DBCC CHECKDB.<\/p>\n<p>In the SQL Server error log I am able to see the event:<\/p>\n<p><em>2017-12-09 19:27:06.930 Server\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Error: 7885, Severity: 20, State: 1. <\/em><\/p>\n<p><em>2017-12-09 19:27:06.930 Server\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Network error 0x2746 occurred while sending data to the client on process ID 57 batch ID 0. A common cause for this error is if the client disconnected without reading the entire response from the server. This connection will be terminated.<\/em><\/p>\n<p>Using XP_READERRORLOG, I am able to see the error log in the results tab of a query window.\u00a0 With this information, I was able to see that the network error was cause by a client disconnect.\u00a0 This would shift my focus from SQL Server back to the client server.<\/p>\n<p><a href=\"http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2017\/12\/Errorlog4029.jpg\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-1522 size-full\" src=\"http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2017\/12\/Errorlog4029.jpg\" alt=\"Error: 7885, Severity: 20, State: 1.\" width=\"1358\" height=\"375\" srcset=\"http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2017\/12\/Errorlog4029.jpg 1358w, http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2017\/12\/Errorlog4029-300x83.jpg 300w, http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2017\/12\/Errorlog4029-768x212.jpg 768w, http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2017\/12\/Errorlog4029-1024x283.jpg 1024w, http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2017\/12\/Errorlog4029-210x58.jpg 210w\" sizes=\"(max-width: 1358px) 100vw, 1358px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Problem: About once a month, I get support ticket regarding SQL Server dropping an application&#8217;s or user&#8217;s connection.\u00a0 The problem is SQL Server does not just randomly drop a connection &hellip; <a class=\"readmore\" href=\"http:\/\/www.theSQLReport.com\/?p=1514\">Continue Reading &rarr;<\/a><\/p>\n","protected":false},"author":1,"featured_media":1521,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[117,118,119,116],"class_list":["post-1514","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-sql-server","tag-117","tag-dbcc-traceon","tag-network-error","tag-trace-flag"],"_links":{"self":[{"href":"http:\/\/www.theSQLReport.com\/index.php?rest_route=\/wp\/v2\/posts\/1514"}],"collection":[{"href":"http:\/\/www.theSQLReport.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.theSQLReport.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.theSQLReport.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.theSQLReport.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1514"}],"version-history":[{"count":10,"href":"http:\/\/www.theSQLReport.com\/index.php?rest_route=\/wp\/v2\/posts\/1514\/revisions"}],"predecessor-version":[{"id":1528,"href":"http:\/\/www.theSQLReport.com\/index.php?rest_route=\/wp\/v2\/posts\/1514\/revisions\/1528"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.theSQLReport.com\/index.php?rest_route=\/wp\/v2\/media\/1521"}],"wp:attachment":[{"href":"http:\/\/www.theSQLReport.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1514"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.theSQLReport.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1514"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.theSQLReport.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1514"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}