<?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>SqlDataReader performance tips</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2006/07/12/sqldatareader-performance-tips.aspx</link><description>I just posted a few SqlDataReader performance tips in response to a newsgroup post; I think they're some pretty good tips, so I'll repeat them here. These tips were gleaned from using both Lutz Roeder's Reflector and Compuware's DevPartner Profiler Community</description><dc:language>en</dc:language><generator>CommunityServer 2.1 SP2 (Build: 61129.1)</generator><item><title>re: SqlDataReader performance tips</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2006/07/12/sqldatareader-performance-tips.aspx#8676</link><pubDate>Sun, 31 Aug 2008 18:44:25 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:8676</guid><dc:creator>RP</dc:creator><description>&lt;p&gt;Re: (B) above.&lt;/p&gt;
&lt;p&gt;With the latest ADO.NET libraries (as of .NET 3.5), the GetXXX methods for value types (GetInt32/GetDateTime etc) are approximately 10 - 15% faster compared to the cast approach (i'm guessing because the box/unbox overhead of converting to an object and back is avoided).&lt;/p&gt;
&lt;p&gt;The performance is roughly the same for something like GetString &amp;nbsp;vs (string) reader[0] - either of which create an object on the heap anyway.&lt;/p&gt;
</description></item><item><title>re: SqlDataReader performance tips</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2006/07/12/sqldatareader-performance-tips.aspx#9688</link><pubDate>Mon, 27 Oct 2008 14:16:19 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:9688</guid><dc:creator>David</dc:creator><description>&lt;p&gt;Is what RP said true?&lt;/p&gt;
&lt;p&gt;Cause I really don't see how this could be since your sending the data from the SqlDataReader to a value type?&lt;/p&gt;
&lt;p&gt;I wouldn't be surpised SqlDataReader would be holding objects/references in the background so I wonder how boxing/unboxing can be avoided by using hte GetXXX methods.&lt;/p&gt;
&lt;p&gt;Thanks.&lt;/p&gt;
</description></item><item><title>re: SqlDataReader performance tips</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2006/07/12/sqldatareader-performance-tips.aspx#9693</link><pubDate>Mon, 27 Oct 2008 19:44:05 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:9693</guid><dc:creator>David</dc:creator><description>&lt;p&gt;Nevermind me, apparently good pratices since ADO.NET 2.0...&lt;/p&gt;
</description></item><item><title>re: SqlDataReader performance tips</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2006/07/12/sqldatareader-performance-tips.aspx#16864</link><pubDate>Fri, 18 Sep 2009 14:46:54 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:16864</guid><dc:creator>AP</dc:creator><description>&lt;p&gt;I can confirm what David is saying. We did some tests and using the GetXXX methods resulted in being 10% faster than using the reader[i] indexer method.&lt;/p&gt;
</description></item><item><title>re: SqlDataReader performance tips</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2006/07/12/sqldatareader-performance-tips.aspx#26503</link><pubDate>Mon, 28 Jun 2010 11:49:49 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:26503</guid><dc:creator>Ashish Gupta</dc:creator><description>&lt;p&gt;GetXXX() methods are definitely faster than the cast. &lt;/p&gt;
&lt;p&gt;&lt;a rel="nofollow" target="_new" href="http://support.microsoft.com/kb/310348"&gt;http://support.microsoft.com/kb/310348&lt;/a&gt;&lt;/p&gt;
</description></item><item><title>re: SqlDataReader performance tips</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2006/07/12/sqldatareader-performance-tips.aspx#26509</link><pubDate>Mon, 28 Jun 2010 13:53:27 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:26509</guid><dc:creator>Adam Machanic</dc:creator><description>&lt;p&gt;Yup, I agree that in current versions of ADO.NET the getters are a much better choice. When I originally wrote this post -- sometime in 2004 -- the casts were faster in my tests.&lt;/p&gt;&lt;p&gt;The other two tips are still 100% valid--use of the ordinal indexer and paying attention to releasing connections as quickly as possible are important keys for maximizing performance.&lt;br&gt;&lt;/p&gt;</description></item><item><title>re: SqlDataReader performance tips</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2006/07/12/sqldatareader-performance-tips.aspx#45264</link><pubDate>Tue, 18 Sep 2012 20:58:13 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:45264</guid><dc:creator>John Glasgow</dc:creator><description>&lt;p&gt;Awesome post! I saw GetOrdinal for years but never made the connection that it was called every time. Boosted the performance of a query I was working on by about 25%.&lt;/p&gt;
</description></item></channel></rss>