<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://www2.sqlblog.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>The client code that handles timeouts</title><link>http://www2.sqlblog.com/blogs/alexander_kuznetsov/archive/2013/01/10/the-client-code-that-handles-timeouts.aspx</link><description>After timeouts we need to make sure that active transactions, if any, are rolled back. All timeout handling must be done on the client. This post provides the implementation and unit tests. Implementation The following class extends SqlCommand and rolls</description><dc:language>en</dc:language><generator>CommunityServer 2.1 SP2 (Build: 61129.1)</generator><item><title>re: The client code that handles timeouts</title><link>http://www2.sqlblog.com/blogs/alexander_kuznetsov/archive/2013/01/10/the-client-code-that-handles-timeouts.aspx#47112</link><pubDate>Fri, 11 Jan 2013 11:15:54 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:47112</guid><dc:creator>gbn</dc:creator><description>&lt;p&gt;Why not use SET XACT_ABORT ON so the client code doesn't need to run anything?&lt;/p&gt;
&lt;p&gt;Example: code crashes but connections stays open in the connection pool.&lt;/p&gt;
&lt;p&gt;See my answers on SO &lt;a rel="nofollow" target="_new" href="http://stackoverflow.com/search?tab=votes&amp;amp;q=user%3a27535%20%2bset%20%2bxact_abort"&gt;http://stackoverflow.com/search?tab=votes&amp;amp;q=user%3a27535%20%2bset%20%2bxact_abort&lt;/a&gt;&lt;/p&gt;
</description></item><item><title>re: The client code that handles timeouts</title><link>http://www2.sqlblog.com/blogs/alexander_kuznetsov/archive/2013/01/10/the-client-code-that-handles-timeouts.aspx#47113</link><pubDate>Fri, 11 Jan 2013 13:58:44 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:47113</guid><dc:creator>dan holmes</dc:creator><description>&lt;p&gt;This seems to be a behavior only when 'Connection Pooling' is on. &amp;nbsp;If you add 'Pooling=False' to the connection string, then the moment the connection object goes out of scope or is closed both the connection and transaction are gone.&lt;/p&gt;
&lt;p&gt;--&lt;/p&gt;
&lt;p&gt;dan&lt;/p&gt;
&lt;p&gt;&lt;a rel="nofollow" target="_new" href="http://dnhlmssql.blogspot.com/"&gt;http://dnhlmssql.blogspot.com/&lt;/a&gt;&lt;/p&gt;
</description></item><item><title>re: The client code that handles timeouts</title><link>http://www2.sqlblog.com/blogs/alexander_kuznetsov/archive/2013/01/10/the-client-code-that-handles-timeouts.aspx#47118</link><pubDate>Fri, 11 Jan 2013 18:58:55 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:47118</guid><dc:creator>Adam Machanic</dc:creator><description>&lt;p&gt;gbn: XACT_ABORT will *not* abort the transaction in case of an Attention event (a.k.a. timeout). &lt;/p&gt;
&lt;p&gt;dan: sure, we could disable connection pooling. But now you've taken a major, major performance and scalability hit. Is it worth it? No way. Use Alex's code (or roll your own) and keep pooling wherever possible.&lt;/p&gt;
</description></item><item><title>re: The client code that handles timeouts</title><link>http://www2.sqlblog.com/blogs/alexander_kuznetsov/archive/2013/01/10/the-client-code-that-handles-timeouts.aspx#47121</link><pubDate>Fri, 11 Jan 2013 21:01:01 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:47121</guid><dc:creator>Alexander Kuznetsov</dc:creator><description>&lt;p&gt;@gbn: on one hand, Ken Henderson clearly stated in his blog &amp;quot;There's no such thing as a query timeout&amp;quot;: &amp;quot;An attention tells the server to cancel the connection's currently executing query (if there is one) as soon as possible. &amp;nbsp;An attention doesn't rollback open transactions&amp;quot;. Of course, it was written long ago, on 20 Oct 2005.&lt;/p&gt;
&lt;p&gt;On the other hand, I just ran a few tests, and XACT_ABORT ON consistently rolls back after a timeout. Does it always do so? Dan Guzman thinks so: &amp;quot;Use Caution with Explicit Transactions in Stored Procedures&amp;quot;. Because SQL Server is not open source, we cannot verify ourselves...&lt;/p&gt;
</description></item><item><title>re: The client code that handles timeouts</title><link>http://www2.sqlblog.com/blogs/alexander_kuznetsov/archive/2013/01/10/the-client-code-that-handles-timeouts.aspx#47122</link><pubDate>Fri, 11 Jan 2013 21:02:33 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:47122</guid><dc:creator>Alexander Kuznetsov</dc:creator><description>&lt;p&gt;@Dan Holmes: in my experience not using connection pooling is usually more expensive than using it.&lt;/p&gt;
</description></item><item><title>re: The client code that handles timeouts</title><link>http://www2.sqlblog.com/blogs/alexander_kuznetsov/archive/2013/01/10/the-client-code-that-handles-timeouts.aspx#47134</link><pubDate>Sat, 12 Jan 2013 17:50:07 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:47134</guid><dc:creator>Adam Machanic</dc:creator><description>&lt;p&gt;@alex and @gbn: I just ran some tests as well, and it seems this did change at some point -- XACT_ABORT does indeed always roll back the transaction when an Attention event occurs.&lt;/p&gt;
&lt;p&gt;Here's another reference from Microsoft: &lt;a rel="nofollow" target="_new" href="https://blogs.msdn.com/b/psssql/archive/2008/07/23/how-it-works-attention-attention-or-should-i-say-cancel-the-query-and-be-sure-to-process-your-results.aspx"&gt;https://blogs.msdn.com/b/psssql/archive/2008/07/23/how-it-works-attention-attention-or-should-i-say-cancel-the-query-and-be-sure-to-process-your-results.aspx&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;quot;At the time of the attention the transaction is not rolled back unless transaction abort (XACT_ABORT) has been enabled.&amp;quot;&lt;/p&gt;
&lt;p&gt;--Adam&lt;/p&gt;
</description></item><item><title>re: The client code that handles timeouts</title><link>http://www2.sqlblog.com/blogs/alexander_kuznetsov/archive/2013/01/10/the-client-code-that-handles-timeouts.aspx#47154</link><pubDate>Mon, 14 Jan 2013 20:46:59 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:47154</guid><dc:creator>Alexander Kuznetsov</dc:creator><description>&lt;p&gt;@gbn I ran more tests, and XACT_ABORT ON consistently rolls back on timeout. Thank you for your comment.&lt;/p&gt;
&lt;p&gt;On one hand, when we handle timeouts on the client, we can implement it only once in one place, as I demonstrated in my code samples. This solves our problem right away.&lt;/p&gt;
&lt;p&gt;On the other hand, we absolutely want to roll back ASAP, so it makes sense to add SET XACT_ABORT ON to all my reading procedures, and redeploy. (All my writes have SET XACT_ABORT ON already.) This is a better solution in the long run.&lt;/p&gt;
&lt;p&gt;@Adam yes probably the behavior changed at some time.&lt;/p&gt;
</description></item><item><title>re: The client code that handles timeouts</title><link>http://www2.sqlblog.com/blogs/alexander_kuznetsov/archive/2013/01/10/the-client-code-that-handles-timeouts.aspx#47434</link><pubDate>Fri, 01 Feb 2013 06:07:49 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:47434</guid><dc:creator>handles</dc:creator><description>&lt;p&gt;I just came onto your post and found it quite interesting. I am also associated with Door Handles, Door knobs, kitchen Door Handles, Door Handles suppliers, Door handles UK, Ironmongery Suppliers, Handles, knobs and love to enjoy the stuff on the same as its rarely found on internet. Thanks again for writing such a good post.&lt;/p&gt;
</description></item></channel></rss>