SQLDataReader.GetOrdinal() fails rarely with IndexOutOfRangeHi everybody,<br /> <br /> We were developed some Web-Services that run against SQL Server 2000 with SQLDataReader that executing Stored Procedures in the DB. Most of time (95%) <font color="#000000">everything is running well, but sometimes (when exactly, we don't know) the same WebService that worked 200 times, fail.<br /> <br /> The code is simple:<br /> <br /> <table border="0" cellspacing="0" width="100%"><tr><td width="15"></td><td bgcolor="lightgrey" width="15"></td><td bgcolor="lightgrey"><br><font face="Lucida Console" size="2"><br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <font color= "blue">public</font> <font color= "blue">string</font> myFunction( <font color= "blue">int</font> ANumber )<br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <font color= "blue">string</font> strRetVal = <font color= "blue">null</font>;<br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; SqlDataReader myReader = <font color= "blue">null</font>;<br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; SqlConnection MyConn = <font color= "blue">null</font>;<br /> <br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <font color= "blue">const</font> <font color= "blue">string</font> SAME_STORED_PROCEDURE_NAME_ALWAYS = "sp1";<br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <font color= "blue">const</font> <font color= "blue">string</font> SAME_PARAM_NAME</font> _ALWAYS = "param2";<br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <font color= "blue">const</font> <font color= "blue">string</font> SAME_FIELD_NAME_ALWAYS = "<font color="#000080">RUSureYouWantThisField</font>";<br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <font color= "blue">const</font> <font color= "blue">string</font> MY_CONNECTION_STR = "Connect me to SQL...";<br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <font color= "blue">try</font><br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br /> <br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; MyConn = <font color= "blue">new</font> SqlConnection( MY_CONNECTION_STR );<br /> <br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; SqlCommand MyCMD = <font color= "blue">new</font> SqlCommand( SAME_STORED_PROCEDURE_NAME_ALWAYS, MyConn );<br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; MyCMD.CommandType = CommandType.StoredProcedure;<br /> <br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; SqlParameter myParm = MyCMD.Parameters.Add( SAME_PARAM_NAME_ALWAYS, SqlDbType.BigInt );<br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; myParm.Value = ANumber;<br /> <br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; MyConn.Open();<br /> <br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; myReader = MyCMD.ExecuteReader();<br /> <br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <font color= "blue">while</font> (myReader.Read())<br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <font color="#008000">strRetVal =&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; myReader[SAME_FIELD_NAME_ALWAYS].ToString();&nbsp; <br /> </font><font color="#000000">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <font color= "blue">break</font>;<br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br /> <br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <font color= "blue">return</font> strRetVal;<br /> <br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <font color= "blue">finally</font><br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <font color= "blue">if</font>&nbsp; (myReader !=<font color= "blue">null</font> &amp;&amp; !myReader.IsClosed)<br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; myReader.Close();<br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <font color= "blue">if</font> (MyConn !=<font color= "blue">null</font>)&nbsp; MyConn.Close();<br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</font><br>&nbsp;</td></tr></table><br /> </font> <br /> <br /> The line marked in <font color="#008000">green </font>throws an exception:<br /> <div class=quote><font class=quoteHeader style=""><font color="#ff0000">System.IndexOutOfRangeException: <font color="#000080">RUSureYouWantThisField</font><br /> &nbsp;&nbsp; at System.Data.Common.FieldNameLookup.GetOrdinal(String fieldName)<br /> &nbsp;&nbsp; at System.Data.SqlClient.SqlDataReader.GetOrdinal(String name)<br /> &nbsp;&nbsp; at System.Data.SqlClient.SqlDataReader.get_Item(String name)<br /> &nbsp;&nbsp; at myFunction()...<br /> </font></div> From the exception it seems that the field nam<font color="#000000">e "</font><font color="#ff0000"><font color="#000080"><font color="#000000">RUSureYouWantThisField" is not part of the SELECTed fields of the stored procedure. BUT: we sure that we didn't touch that table, nor the stored procedure. Moreover - most of time this function finishes its execution well, so we have no clue what going wrong in the rare times it doesn't work.<br /><br /> We Googled it, search this forum and other forums and newsgroups, but we have found only one KB article describes very similar problem when reading field using JDBC. (KB838610, <a target="_blank" title="http://support.microsoft.com/default.aspx?scid=kb;en-us;838610" href="http://support.microsoft.com/default.aspx?scid=kb;en-us;838610">http://support.microsoft.com/default.aspx?scid=kb;en-us;838610</a>).<br /><br /> But:<br /> </font></font></font> <ol> <li><font color="#ff0000"><font color="#000080"><font color="#000000">We deal with SQLClient, not with JDBC.</font></font></font></li> <li><font color="#ff0000"><font color="#000080"><font color="#000000">The latter article suggest workaround to this problem - to explicitly specify the fields in the SELECT statement of the stored procedure. our functions failed either when called to stored procedure with "SELECT * From ..." or when called to stored procedure that SELECTed specific field names.<br /> </font></font></font></li> </ol> <font color="#ff0000"><font color="#000080"><font color="#000000">Did anyone encountered this strange behavior ?<br /> <br /> Thanks in advance,<br /> Yinon<br /> </font></font></font>© 2009 Microsoft Corporation. All rights reserved.Fri, 25 Sep 2009 20:23:20 Z74a5db87-c63f-4386-b317-e848dedb2cd9http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#74a5db87-c63f-4386-b317-e848dedb2cd9http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#74a5db87-c63f-4386-b317-e848dedb2cd9Yinonhttp://social.msdn.microsoft.com/Profile/en-US/?user=YinonSQLDataReader.GetOrdinal() fails rarely with IndexOutOfRangeHi everybody,<br /> <br /> We were developed some Web-Services that run against SQL Server 2000 with SQLDataReader that executing Stored Procedures in the DB. Most of time (95%) <font color="#000000">everything is running well, but sometimes (when exactly, we don't know) the same WebService that worked 200 times, fail.<br /> <br /> The code is simple:<br /> <br /> <table border="0" cellspacing="0" width="100%"><tr><td width="15"></td><td bgcolor="lightgrey" width="15"></td><td bgcolor="lightgrey"><br><font face="Lucida Console" size="2"><br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <font color= "blue">public</font> <font color= "blue">string</font> myFunction( <font color= "blue">int</font> ANumber )<br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <font color= "blue">string</font> strRetVal = <font color= "blue">null</font>;<br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; SqlDataReader myReader = <font color= "blue">null</font>;<br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; SqlConnection MyConn = <font color= "blue">null</font>;<br /> <br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <font color= "blue">const</font> <font color= "blue">string</font> SAME_STORED_PROCEDURE_NAME_ALWAYS = "sp1";<br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <font color= "blue">const</font> <font color= "blue">string</font> SAME_PARAM_NAME</font> _ALWAYS = "param2";<br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <font color= "blue">const</font> <font color= "blue">string</font> SAME_FIELD_NAME_ALWAYS = "<font color="#000080">RUSureYouWantThisField</font>";<br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <font color= "blue">const</font> <font color= "blue">string</font> MY_CONNECTION_STR = "Connect me to SQL...";<br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <font color= "blue">try</font><br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br /> <br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; MyConn = <font color= "blue">new</font> SqlConnection( MY_CONNECTION_STR );<br /> <br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; SqlCommand MyCMD = <font color= "blue">new</font> SqlCommand( SAME_STORED_PROCEDURE_NAME_ALWAYS, MyConn );<br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; MyCMD.CommandType = CommandType.StoredProcedure;<br /> <br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; SqlParameter myParm = MyCMD.Parameters.Add( SAME_PARAM_NAME_ALWAYS, SqlDbType.BigInt );<br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; myParm.Value = ANumber;<br /> <br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; MyConn.Open();<br /> <br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; myReader = MyCMD.ExecuteReader();<br /> <br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <font color= "blue">while</font> (myReader.Read())<br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <font color="#008000">strRetVal =&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; myReader[SAME_FIELD_NAME_ALWAYS].ToString();&nbsp; <br /> </font><font color="#000000">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <font color= "blue">break</font>;<br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br /> <br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <font color= "blue">return</font> strRetVal;<br /> <br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <font color= "blue">finally</font><br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <font color= "blue">if</font>&nbsp; (myReader !=<font color= "blue">null</font> &amp;&amp; !myReader.IsClosed)<br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; myReader.Close();<br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <font color= "blue">if</font> (MyConn !=<font color= "blue">null</font>)&nbsp; MyConn.Close();<br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br /> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</font><br>&nbsp;</td></tr></table><br /> </font> <br /> <br /> The line marked in <font color="#008000">green </font>throws an exception:<br /> <div class=quote><font color="#ff0000">System.IndexOutOfRangeException: <font color="#000080">RUSureYouWantThisField</font><br /> &nbsp;&nbsp; at System.Data.Common.FieldNameLookup.GetOrdinal(String fieldName)<br /> &nbsp;&nbsp; at System.Data.SqlClient.SqlDataReader.GetOrdinal(String name)<br /> &nbsp;&nbsp; at System.Data.SqlClient.SqlDataReader.get_Item(String name)<br /> &nbsp;&nbsp; at myFunction()...<br /> </font></div> From the exception it seems that the field nam<font color="#000000">e "</font><font color="#ff0000"><font color="#000080"><font color="#000000">RUSureYouWantThisField" is not part of the SELECTed fields of the stored procedure. BUT: we sure that we didn't touch that table, nor the stored procedure. Moreover - most of time this function finishes its execution well, so we have no clue what going wrong in the rare times it doesn't work.<br /><br /> We Googled it, search this forum and other forums and newsgroups, but we have found only one KB article describes very similar problem when reading field using JDBC. (KB838610, <a target="_blank" title="http://support.microsoft.com/default.aspx?scid=kb;en-us;838610" href="http://support.microsoft.com/default.aspx?scid=kb;en-us;838610">http://support.microsoft.com/default.aspx?scid=kb;en-us;838610</a>).<br /><br /> But:<br /> </font></font></font> <ol> <li><font color="#ff0000"><font color="#000080"><font color="#000000">We deal with SQLClient, not with JDBC.</font></font></font></li> <li><font color="#ff0000"><font color="#000080"><font color="#000000">The latter article suggest workaround to this problem - to explicitly specify the fields in the SELECT statement of the stored procedure. our functions failed either when called to stored procedure with "SELECT * From ..." or when called to stored procedure that SELECTed specific field names.<br /> </font></font></font></li> </ol> <font color="#ff0000"><font color="#000080"><font color="#000000">Did anyone encountered this strange behavior ?<br /> <br /> Thanks in advance,<br /> Yinon<br /> </font></font></font>Wed, 16 Nov 2005 14:02:03 Z2008-03-24T21:59:21Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#48b98769-ffad-4a2e-9f8a-4036645da7a7http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#48b98769-ffad-4a2e-9f8a-4036645da7a7Kevin Wuhttp://social.msdn.microsoft.com/Profile/en-US/?user=Kevin%20WuSQLDataReader.GetOrdinal() fails rarely with IndexOutOfRangeYinon,<br /><br />I have the same suspension as yours&nbsp;that the sp doesn't return the field "RUSureYouWantThisField" field on some cases (either on special value of input parameter or db/table issue). Could you try calling myReader.GetSchemaTable() and logging&nbsp;the schema&nbsp;before reading the field? This&nbsp;may help you&nbsp;identifying the issue.<br /><br />Thanks,<br />Kevin<br />&nbsp;&nbsp;Fri, 09 Dec 2005 23:25:44 Z2005-12-09T23:25:44Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#d379d932-8651-435b-b08b-2eeb24199e9fhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#d379d932-8651-435b-b08b-2eeb24199e9fbalihttp://social.msdn.microsoft.com/Profile/en-US/?user=baliSQLDataReader.GetOrdinal() fails rarely with IndexOutOfRangeHi ,<br> <br> Even i am facing the same problem, could any body give a solution for that.&nbsp; <br> <br> thanks&nbsp; in advance<br> Bali Reddy <br> <br> Thu, 29 Dec 2005 23:19:07 Z2005-12-29T23:19:07Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#d9e3190d-92ef-4648-bdb2-3f093bdc298dhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#d9e3190d-92ef-4648-bdb2-3f093bdc298dBen Fidgehttp://social.msdn.microsoft.com/Profile/en-US/?user=Ben%20FidgeSQLDataReader.GetOrdinal() fails rarely with IndexOutOfRange<p>This happens on my project almost every day but the code that actually reads from the DB hasn't changed in over 2 years, but now randomly throws these errors for no apparent reason.</p> <p>There's no real pattern and 99% of the time everything works as expected, but the other 1%, these GetOrdinall() IndexOutOfRangeException's occur.</p> <p>Would really like to know what's going on. Is this an ADO.NET 2.0 error or a Sql Server 2005 error? </p> <p>My custom is really getting on my case about this and it was me that recommended investing the money to upgrade to ASP.NET 2.0 and Sql Server 2005 and it's starting to get embarrasing.</p> <p> </p> <p>Ben</p> <p> </p> <p> </p>Thu, 29 Jun 2006 12:39:10 Z2006-06-29T12:39:10Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#20a9743e-7e8a-4dd3-9e2a-056db9ee757bhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#20a9743e-7e8a-4dd3-9e2a-056db9ee757balazelahttp://social.msdn.microsoft.com/Profile/en-US/?user=alazelaSQLDataReader.GetOrdinal() fails rarely with IndexOutOfRangeThere are a couple of possibilities:<br><br>1) The field name isn't being returned from the stored procedure call (as a couple of people have mentioned).<br>  The best way to determine this problem is to actually enumerate the fields and compare the names manually, either in a debugger or by printing them out to a log or error message.  In the latter case, I'd suggest only enumerating &amp; printing the fields when the exception occurs by putting in a catch block that explicitly catches IndexOutOfRange errors.<br><br>2) Field name differs subtly, and the comparison is sensitive to the difference (i.e. case sensitivity).  Field name comparisons are done based on the server's collation.  New to Sql2005 accessed from ADO.Net v2 is that changes in language at the server will be reflected in the name comparison on the client.  This is really a sub-case of my first listed item, so use the same method to determine if it's a problem, but look for ANY differences between the field name and the name you are looking up.<br><br>3) A bug in ADO.Net.  This area has been fairly heavily tested, but it's always possible. :-(<br>  If you've carefully ruled out 1 &amp; 2 as possibilities, please post a precise scenario showing working stored procedure and client code that demonstrates the problem.<br>Thu, 29 Jun 2006 15:47:47 Z2008-03-24T21:59:21Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#2874681b-ef81-45cf-9a81-7a79f3429a13http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#2874681b-ef81-45cf-9a81-7a79f3429a13Ben Fidgehttp://social.msdn.microsoft.com/Profile/en-US/?user=Ben%20FidgeSQLDataReader.GetOrdinal() fails rarely with IndexOutOfRange<p>Hi Alazel</p> <p>Thanks for the advice. I'll add enumeration code so that I can see the field names being returned.</p> <p>The real confusing issue is that 99% of the time these fields are returned fine which makes it very difficult to recreate the error. I've tried isolating the code and running it with 20+ concurrent users and it will on occasion fall over, but very rarely, and there doesn't seem to be any pattern. The same offending field names keep popping up, but the error happens inconsistently.</p> <p>Don't know if this is significant but my db was originally Sql Server 2000 and we recently went over to 2005. These errors have only been occuring since then. We've installed the latest service pack BTW.</p> <p>A lot of my views contained &quot;select *&quot; statements with &quot;joins&quot; to other tables. I've resaved all my views using Sql Management Studio so that the full field names are specified instead of &quot;*&quot;. I haven't had the error occur on my test system since then, but admittedly, haven't had time to do the same stress testing I did yesterday. Could this be it? </p> <p>If this turns out to be a fix, i'll let you know.</p> <p>Ben</p> <p> </p> <p> </p>Fri, 30 Jun 2006 14:29:17 Z2006-06-30T14:29:17Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#a6feb578-7aa6-4c77-b26a-882a7aa05840http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#a6feb578-7aa6-4c77-b26a-882a7aa05840alazelahttp://social.msdn.microsoft.com/Profile/en-US/?user=alazelaSQLDataReader.GetOrdinal() fails rarely with IndexOutOfRange<p dir=ltr style="margin-right:0px">Changing views from '*' to manual field enumeration could have some effect, but mainly if you've mis-matched fieldname casing in you ADO.Net code on a case sensitive server (or similar comparison issue), and your view now modifies the name.  If you specify the view column names precisely as they appear in the tables, though, it shouldn't have made a difference.</p> <p dir=ltr style="margin-right:0px">I'm pretty suspicious of the comparison style mismatch possibility, especially since the problem turned up after moving to Sql 2005.  Did you update the client's to ADO.Net v2 at the same time, or were you already running v2 clients prior?</p>Fri, 30 Jun 2006 16:34:13 Z2006-06-30T16:34:13Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#0f485494-f510-4e6e-b2be-f37cfb478119http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#0f485494-f510-4e6e-b2be-f37cfb478119Ben Fidgehttp://social.msdn.microsoft.com/Profile/en-US/?user=Ben%20FidgeSQLDataReader.GetOrdinal() fails rarely with IndexOutOfRangeHi AlazelMon, 03 Jul 2006 11:06:06 Z2006-07-03T11:06:06Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#31f1f669-31b0-4f7a-99e4-909ed9d30051http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#31f1f669-31b0-4f7a-99e4-909ed9d30051Ben Fidgehttp://social.msdn.microsoft.com/Profile/en-US/?user=Ben%20FidgeSQLDataReader.GetOrdinal() fails rarely with IndexOutOfRange<p>Hi Alazel</p> <p>I can see your point about the comparison style mismatch but why would this work most of the time, but then randomly fail, and then carry on working. It makes no sense. As far as I can tell the only factor that varies is the load on the server. </p> <p>The same stored procedures, and C# code are being executed time after time, and as mentioned, work fine most of the time. It's just the random nature of the IndexOutOfRange exceptions that are really making this difficult to diagnose. </p> <p>Our entire project went over to Sql Server 2005 and ADO.NET 2.0 at the same time so can't comment about the situation running as ADO.NET 2.0 and Sql Server 2000.</p> <p>Ben</p> <p> </p>Mon, 03 Jul 2006 11:11:34 Z2006-07-03T11:11:34Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#c86137cc-2b4d-4c12-bb54-c58bbaf6230chttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#c86137cc-2b4d-4c12-bb54-c58bbaf6230calazelahttp://social.msdn.microsoft.com/Profile/en-US/?user=alazelaSQLDataReader.GetOrdinal() fails rarely with IndexOutOfRangeThe intermittant nature definitely makes things difficult to diagnose acurately.  I've seen this type of behavior when the stored procedure actually has conditional logic switching which statement actually returns the results, and the comparison error happens in one location, but not the other.<br><br>Having behavior vary depending on server load is interesting.  Does the problem ONLY occur when the server is under a heavy load?  Sometimes, when the server is under a strain and resource failures start happening, things can get a bit tricky with returned error codes, sometimes defering the actual error to the next resultset (it wouldn't show up until a NextResults() call).  Is it possible the server actually returned a different error that just hasn't been thrown yet?<br><br>One other thing to check for -- before indexing into the reader to get the value, check the FieldCount.  If there are no Fields (or significantly fewer than expected), this could be the issue.<br>Mon, 03 Jul 2006 20:18:06 Z2006-07-03T20:18:06Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#7e4305eb-1673-4485-94cf-1f4c30290836http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#7e4305eb-1673-4485-94cf-1f4c30290836William Vaughnhttp://social.msdn.microsoft.com/Profile/en-US/?user=William%20VaughnSQLDataReader.GetOrdinal() fails rarely with IndexOutOfRange<p>I suspect that the SP is not returning a rowset in some (rare) cases. Try adding a </p> <p>myReader.HasRows</p> <p>test to see if there are any rows before attempting to access the row values.</p> <p> </p> <p>hth</p>Tue, 04 Jul 2006 05:29:38 Z2006-07-04T05:29:38Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#5a12d1a6-13ae-4aad-9b90-1b2090e36fcbhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#5a12d1a6-13ae-4aad-9b90-1b2090e36fcbphamdachoanghttp://social.msdn.microsoft.com/Profile/en-US/?user=phamdachoangSQLDataReader.GetOrdinal() fails rarely with IndexOutOfRange<p> </p> <p>You should create a function to return a datareader, and when using, bebore calling the sequence </p> <p>while (datareader.Read())</p> <p>{</p> <p>}</p> <p>you should check as the following code</p> <p> if (!datareader.HasRows) return;</p> <p>*************************************************</p> <p>I also create a function that call store procedures in SQL, but I write in VB.NET</p> <p>You can change it to C# easily, by replacing this module in to class</p> <p> </p><font size=2> <p>Imports System.Data.SqlClient</p> <p>Module ConnectSql</p><font size=2> <p>'name of the database server </p> <p>Public Server As String  'name </p> <p>'database name</p> <p>Public Database As String</p> <p>Public UserID As String</p> <p>' connection object</p></font><font size=2> <p>Public con As SqlConnection</p><font size=2> <p>#Region &quot;Manage the connection existed or not&quot;</p> <p>Public Function OpenSqL() As SqlConnection</p> <p>If Exist() = True Then</p> <p>Return con</p> <p>End If</p> <p>Try</p> <p>Dim conString As String</p> <p>conString = &quot;data source=&quot; &amp; Server &amp; &quot;;initial catalog=&quot; &amp; Database &amp; &quot;;persist security info=False;user id=&quot; &amp; UserID &amp; &quot;;pwd=&quot; &amp; Password</p> <p>con = New SqlConnection(conString)</p> <p>con.Open()</p> <p>Catch ex As Exception</p> <p>con = Nothing</p> <p>End Try</p> <p>Return con</p> <p>End Function</p> <p>Public Sub CloseSql()</p> <p>Try</p> <p>If con.State &lt;&gt; ConnectionState.Closed Then</p> <p>con.Close()</p> <p>End If</p> <p>Catch ex As Exception</p> <p>Throw ex</p> <p>End Try</p> <p>con = Nothing</p> <p>End Sub</p> <p>Private Function Exist() As Boolean</p> <p>If con Is Nothing Then</p> <p>Return False</p> <p>Else</p> <p>Return True</p> <p>End If</p> <p>End Function</p> <p>#End Region</p> <p>' this function is used to call Store procedures </p> <p>' after calling, it return a datareader</p> <p>'optional paramenters ( parameters of the store procedure called)</p> <p>'optional value values of each parameter</p> <p> </p></font></font></font><font size=2> <p>Public Function SP_Select(ByVal sp_name As String, Optional ByVal params() As String = Nothing, Optional ByVal values() As Object = Nothing) As SqlDataReader</p> <p>Dim dr As SqlDataReader = Nothing</p> <p>Try</p> <p>Dim command As SqlCommand = New SqlCommand(sp_name, OpenSqL())</p> <p>' set type of command</p> <p>command.CommandType = CommandType.StoredProcedure</p> <p>' check if the parameters are passed into the function </p> <p>If (Not params Is Nothing) Then</p> <p>Dim len As Integer = params.Length - 1</p> <p>Dim i As Integer</p> <p>For i = 0 To len</p> <p>command.Parameters.Add(New SqlParameter(params(i), values(i)))</p> <p>Next</p> <p>End If</p> <p>dr = command.ExecuteReader()</p> <p>Catch ex As Exception</p> <p>MessageBox.Show(ex.ToString)</p> <p>dr = Nothing</p> <p>Throw ex</p> <p>End Try</p> <p>Return dr</p> <p>End Function</p> <p></font> End Module</p> <p> </p>Tue, 04 Jul 2006 07:59:57 Z2006-07-04T07:59:57Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#1dfb8c31-26aa-46a3-9f7d-2fe031c83ecehttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#1dfb8c31-26aa-46a3-9f7d-2fe031c83ecebarryhaganhttp://social.msdn.microsoft.com/Profile/en-US/?user=barryhaganSQLDataReader.GetOrdinal() fails rarely with IndexOutOfRangeWe are also seeing the same thing with a web application....  the vast majority of calls to the database work fine, and then it will just start happening.  Once we get into this error state, all calls to the database fail with the same IndexOutOfRange Exception.  We will see different column names in the exception depending on what table the reader was attempting to use.   We recover by restarting IIS.<br><br>Our environment is ASP.Net 1.1 on x64 2003 Server SP1 using a SQL2005 SP1 database on another x64 2003 Server SP1.  (IIS 6 is running in 32bit compat. mode for our .Net 1.1 web app)<br><br>For now our only solution is to use an external monitoring program to detect this condition and restart IIS.<br><br><br>Tue, 18 Jul 2006 01:01:24 Z2006-07-18T01:01:24Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#9d2f528f-759d-4dae-8cae-8edfde9bcd7dhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#9d2f528f-759d-4dae-8cae-8edfde9bcd7dalazelahttp://social.msdn.microsoft.com/Profile/en-US/?user=alazelaSQLDataReader.GetOrdinal() fails rarely with IndexOutOfRange<p>If you can follow the steps I posted previously to capture the exception and log the field names included in the reader for comparison with the string you are using to index, that might help sort out the problem.</p> <p>If you can do this, please also log the exception details (message, call stack and inner exception details, if any).  If you can post these details, I can take a closer look at the code to try to narrow things down a bit.</p>Wed, 19 Jul 2006 19:52:37 Z2006-07-19T19:52:37Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#bfadfe07-e33f-4c3b-844d-0931cd8b90c4http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#bfadfe07-e33f-4c3b-844d-0931cd8b90c4R Hillhttp://social.msdn.microsoft.com/Profile/en-US/?user=R%20HillSQLDataReader.GetOrdinal() fails rarely with IndexOutOfRange<P>Barry,</P> <P>I am experiencing the exact&nbsp;same symptoms in a web app. Once the first error occurrs, no reader seems to get back the column names that are expected and recycling the app is the only way to clear it up. The problem appears to occur randomly and very rarely (3 x in the last 2 months).</P> <P>My environment is asp.net 1.1 on x64&nbsp;Win2K Server SP4 (IIS 5)&nbsp;using a SQL2000 db on another x64 Win2K Server SP4.</P> <P>Considering that our commonality is asp.net 1.1, I am suspecting a problem with that. Further, since it appears to affect everyone, I am wondering if there is a problem in the connection pool since that is the only real commonality between the various readers. What is your opinion?</P> <P>&nbsp;</P>Tue, 01 Aug 2006 15:56:16 Z2006-08-01T15:56:16Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#6c26dbcf-b624-4eb8-90c5-c967e4416274http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#6c26dbcf-b624-4eb8-90c5-c967e4416274sofohttp://social.msdn.microsoft.com/Profile/en-US/?user=sofoSQLDataReader.GetOrdinal() fails rarely with IndexOutOfRange&nbsp;Thu, 17 Aug 2006 02:14:45 Z2006-08-17T02:14:45Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#5a8a0878-0e9c-4fa5-a973-60f1921ceb5ehttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#5a8a0878-0e9c-4fa5-a973-60f1921ceb5ebarryhaganhttp://social.msdn.microsoft.com/Profile/en-US/?user=barryhaganSQLDataReader.GetOrdinal() fails rarely with IndexOutOfRange<span> <p>Ok, I got it to happen again with enough debug code.</p> <p><font face="Verdana">What is happening is that the reader is filled with data from the wrong table. It would seem to be a caching/pooling problem in ado.net where the reader or the reader's content changes beneath me.</font><font size="2"></font></p> <p>This is what I am throwing after catching the exception in GetOrdinal(string name) (I'm creating a new exception of the same type with additional info):</p> <p>===================================================<br>Exception Occurred: <br>System.IndexOutOfRangeException:GetOrdinal failed: IsClosed=False FieldCount=4 (field 0 is Grouping_id) (field 1 is Grouping_description) (field 2 is Grouping_visible) (field 3 is Grouping_name) <br> at SfData.SfDataReader.GetOrdinal(String name)<br> at MsWebsite.Database.SearchHomeImpl.ReadOrdinals(IDataReader reader)<br> at MsWebsite.Database.SearchHomeImpl.FindMultipleByDml(DmlSelect select, SearchOrderBy searchOrderBy)<br>InnerException: System.IndexOutOfRangeException:Search_id<br> at System.Data.Common.FieldNameLookup.GetOrdinal(String fieldName)<br> at System.Data.SqlClient.SqlDataReader.GetOrdinal(String name)<br> at SfData.SfDataReader.GetOrdinal(String name)<br>===================================================<br><br></p> <p>The fields should have been: Search_id, Search_search, Search_submitdate, Search_views. When this starts happening, we always get a reader filled with the wrong table, but the contents can be from different tables (it is just always different than the table we asked for)</p> <p>Bug?</p><p>This is not due to stored procedures because we do not use them... Here is the abbreviated code being used:</p><br>IDataReader reader = null;<br>string select = "SELECT TOP 10 Search.id AS Search_id,Search.search AS Search_search,Search.submitdate AS Search_submitdate,Search.views AS Search_views FROM Search ORDER BY Search.submitdate DESC";<br>reader = myConnection.ExecuteQuery(select);<br>if(!m_OrdinalsSet)<br>{<br>&nbsp;&nbsp;&nbsp; m_idOrdinal = reader.GetOrdinal(Search_id);&nbsp; //crash here<br>&nbsp;&nbsp;&nbsp; m_searchOrdinal = reader.GetOrdinal(Search_search);<br>}<br></span>Thu, 17 Aug 2006 02:37:18 Z2006-08-17T02:37:18Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#f97338a3-88f9-4ab3-846b-af2e838960dbhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#f97338a3-88f9-4ab3-846b-af2e838960dbarnebjarnehttp://social.msdn.microsoft.com/Profile/en-US/?user=arnebjarneSQLDataReader.GetOrdinal() fails rarely with IndexOutOfRangeSince we ported our solution to .net 2.0 and sqlserver2005 we've seen this happen on rare occations aswell. Did anyone come up with a solution for it?<br>Wed, 13 Sep 2006 15:45:52 Z2006-09-13T15:45:52Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#ae451408-7ca3-4b8f-8271-2bd939eb43b3http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#ae451408-7ca3-4b8f-8271-2bd939eb43b3alazelahttp://social.msdn.microsoft.com/Profile/en-US/?user=alazelaSQLDataReader.GetOrdinal() fails rarely with IndexOutOfRangeGiven the names of the columns you are seeing in the actual reader (grouping_xxx), this looks like a problem with a compute-by statement related to the connection (summary rows being returned by the client).  Is it possible that a compute-by is being appended inside your ExecuteQuery data layer method?  If not, there may be a bug with compute-by handling that spills between uses of a connection in the pool.<br><br>In any case, identifying when the grouping_xxx columns are returned is the next step to identifying where the trouble is.  SQL Profiler is probably the best tool for that.  Once the exception is thrown, locate the problem query in the trace. If it doesn't have a compute-by added, search back on the same spid to see what was the next prior couple of statements executed.  Since this seems to be associated with connection pooling, I suspect you will see an sp_resetconnection call just prior to the failing query, and possibly some transaction-related calls.  What you're looking for is a query that specifies the grouping_xxx column names, probably in a group-by or compute-by.  <br><br>If you know from your code where those columns are projected, you may be able to set up a simpler repro scenario by using just the two queries involved.<br><br>Thu, 14 Sep 2006 16:02:58 Z2006-09-14T16:02:58Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#f5f0a6df-f110-4378-b0dd-98fcf87e7831http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#f5f0a6df-f110-4378-b0dd-98fcf87e7831barryhaganhttp://social.msdn.microsoft.com/Profile/en-US/?user=barryhaganSQLDataReader.GetOrdinal() fails rarely with IndexOutOfRangeWe do not add any compute-by statements to our queries.  After looking at the SQL Profiler, here are the queries in question from the profiler trace:<br><br>SELECT TOP 10 Search.id AS Search_id,Search.search AS Search_search,Search.submitdate AS Search_submitdate,Search.views AS Search_views FROM Search ORDER BY Search.submitdate DESC<br><br>SELECT Grouping.id AS Grouping_id,Grouping.description AS Grouping_description,Grouping.visible AS Grouping_visible,Grouping.name AS Grouping_name FROM Grouping WHERE <br>(Grouping.visible = 1)<br><br>These are in SQLBatch events and there are sp_resetconnection RPC calls between every SQLBatchStarting/SQLBatchCompleted pair.<br><br>Correct me if I'm wrong, but I don't think the profiler on the db server will show me the problem if it is indeed within the client pool and our web application. Restarting the web app fixes the problem, so I assume the database server is returning the correct results for a given SQL query, but my app is receiving the wrong result set from the pool. <br><br>Regardless, I have the Profiler running on my DB server and a packet sniffer setup to capture everything on the wire between the web and db servers.  I will post again when I get another failure event.<br>Fri, 15 Sep 2006 02:15:27 Z2006-09-15T21:57:30Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#ef0d5119-53ad-4b3d-b5dc-5bd41b8a96b0http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#ef0d5119-53ad-4b3d-b5dc-5bd41b8a96b0alazelahttp://social.msdn.microsoft.com/Profile/en-US/?user=alazelaSQLDataReader.GetOrdinal() fails rarely with IndexOutOfRangeFrom the information you've given so far, it's extremely likely that this is indeed a client-side bug.  You're seeing metadata from one result showing up in a reader that should be associated with a different result, and you've verified that the results are supposed to show up on different connections.  Can you contact CSS to open a case file and have them help you capture the full information we'll need to locate the problem?<br>Fri, 15 Sep 2006 22:01:01 Z2006-09-15T22:01:01Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#7096e371-0b00-4722-8064-426d1fa11c54http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#7096e371-0b00-4722-8064-426d1fa11c54Zahirhttp://social.msdn.microsoft.com/Profile/en-US/?user=ZahirSQLDataReader.GetOrdinal() fails rarely with IndexOutOfRange<P>Hi Alazel,</P> <P>We are getting the same error. This happening during the peak timing of our business. We already opened ticket with Microsoft Premium service. Still not able to figure out why this&nbsp;is happening. If you come across any solution or fix please let us know.</P> <P><SPAN> </P> <P>Here is more information about our system.</P> <P>Exception type: IndexOutOfRange</P> <P>WebServer: Microsoft Windows&nbsp;Server&nbsp;2003</P> <P>RAM: 4GB</P> <P>SQL Server:&nbsp; Microsoft SQL Server&nbsp; 2000 - 8.00.2040 (Intel X86) <BR>&nbsp;May 13 2005 18:33:17 <BR>&nbsp;Copyright (c) 1988-2003 Microsoft Corporation<BR>&nbsp;Enterprise Edition on Windows NT 5.2 (Build 3790: Service Pack 1)<BR></P></SPAN> <P>Thanks,</P> <P>Zahir</P>Tue, 19 Sep 2006 17:17:51 Z2006-09-19T17:17:51Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#e24d2d41-5409-40cf-9178-42871d0139d5http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#e24d2d41-5409-40cf-9178-42871d0139d5alazelahttp://social.msdn.microsoft.com/Profile/en-US/?user=alazelaSQLDataReader.GetOrdinal() fails rarely with IndexOutOfRangeIf I see a fix or workaround for incorrect column names coming from the reader, I'll post a link on this thread.  Likewise, if you can, please post the general result of your case (KB article if there is one generated).<br>Wed, 20 Sep 2006 16:58:38 Z2006-09-20T16:58:38Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#8f653518-8e6b-473e-bf3e-8ef6c7e0bde2http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#8f653518-8e6b-473e-bf3e-8ef6c7e0bde2arnebjarnehttp://social.msdn.microsoft.com/Profile/en-US/?user=arnebjarneSQLDataReader.GetOrdinal() fails rarely with IndexOutOfRangeDo you have a ticket id (or something similar) where we can follow the progress of this problem?<br>Fri, 22 Sep 2006 08:00:00 Z2006-09-22T08:00:00Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#d1ce19ab-3c03-49ca-9792-544c63ccc2c3http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#d1ce19ab-3c03-49ca-9792-544c63ccc2c3Zahirhttp://social.msdn.microsoft.com/Profile/en-US/?user=ZahirSQLDataReader.GetOrdinal() fails rarely with IndexOutOfRange<p><span style="font-size:9.5pt;color:black">Hi Arnebjarne,</span></p> <p><span style="font-size:9.5pt;color:black">I can not post the Ticket ID, but if you are from Microsoft and you need it please send a email to zahirhas at hotmail dot com</span></p> <p><span style="font-size:9.5pt;color:black">So far Microsoft not able to simulate or even we not able to simulate this problem, it happens occasionally and mostly during Business peak hours.</span></p> <p><span style="font-size:9.5pt;color:black">Thanks,</span></p> <p><span style="font-size:9.5pt;color:black">Zahir</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><font face="Times New Roman"> </font></p></span>Mon, 25 Sep 2006 16:08:26 Z2006-09-25T16:08:26Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#1e148aad-ada1-4fb8-ba6c-01008dba768ehttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#1e148aad-ada1-4fb8-ba6c-01008dba768eDVDA - I Got Vhttp://social.msdn.microsoft.com/Profile/en-US/?user=DVDA%20-%20I%20Got%20VSQLDataReader.GetOrdinal() fails rarely with IndexOutOfRangeI am experiencing the same error but under different circumstances.<br><br>I am specifically trying to pull out a column by the name and I encounter an error. I am catching the error and writing out all the field names in the datareader to a file. The only columns that should be in the datareader are COLUMN_NAME, DATA_TYPE, IS_NULLABLE, COLUMN_DEFAULT but I am getting a whole list of columns from the other database tables.<br><br>If anyone hears anything from Microsoft or finds a work around please let me know. email me at jblackwell at iw-t dot com.<br><br>Thanks<br><br>-Jason<br>Fri, 29 Sep 2006 13:28:01 Z2006-09-29T13:28:01Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#d23f8abf-48e5-4e93-b509-16b9704db2d9http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#d23f8abf-48e5-4e93-b509-16b9704db2d9Nikolay Sokolovhttp://social.msdn.microsoft.com/Profile/en-US/?user=Nikolay%20SokolovSQLDataReader.GetOrdinal() fails rarely with IndexOutOfRange<p>I am experiencing the same problem when the server is heavily loaded.</p> <p><font face=Verdana>ASP.NET 2.0, </font><font face=Verdana>MS SQL Server 2000</font></p>Thu, 05 Oct 2006 12:52:39 Z2006-10-05T12:52:39Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#895abd47-d23f-4466-9a49-031f35081b6ahttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#895abd47-d23f-4466-9a49-031f35081b6aZahirhttp://social.msdn.microsoft.com/Profile/en-US/?user=ZahirSQLDataReader.GetOrdinal() fails rarely with IndexOutOfRange<p>Few updates:</p> <p>Microsoft recommends not passing the SqlDataReader to another method and avoiding any static methods usage, they are not sure this is the root cause to this Exception.</p> <p>Now when this Exception happens I am logging the SqlDataReader Schema Table also. When I look at the Schema table during the Exception it’s pointing to wrong result.</p> <p>Thanks,<br>Zahir</p>Thu, 05 Oct 2006 15:27:15 Z2006-10-05T15:27:15Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#850ba764-f792-4423-b90f-2b073e799d27http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#850ba764-f792-4423-b90f-2b073e799d27DVDA - I Got Vhttp://social.msdn.microsoft.com/Profile/en-US/?user=DVDA%20-%20I%20Got%20VSQLDataReader.GetOrdinal() fails rarely with IndexOutOfRangeThe only thing that I am supicious of is that this wasn't an issue until recently. It never happened until a few weeks ago and now it happens all the time and nothing has changed in the code.<br>Thu, 05 Oct 2006 18:22:41 Z2006-10-05T18:22:41Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#7ad9f255-19ab-4e64-9542-5768cb7d621dhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#7ad9f255-19ab-4e64-9542-5768cb7d621dShameer A Uhttp://social.msdn.microsoft.com/Profile/en-US/?user=Shameer%20A%20USQLDataReader.GetOrdinal() fails rarely with IndexOutOfRange<p>Hi,</p> <p>I am also having the same problem in my application. The application works most of the time but it fails intermittently.  I tried to list all the column names available in the SqlDataReader object. When it works, the data reader seems to have all the columns in it, but when it fails the data reader seems to be missing the last column in the SELECT query. I tried restarting the application, restarting IIS, but the issue still remains. The application is written in .NET 2.0 and the databases is SQL Server 2005. Please let me know if anyone finds an answer to this issue. </p> <p>Many thanks</p> <p>Shameer</p> <p> </p>Wed, 10 Jan 2007 07:22:51 Z2007-01-10T07:22:51Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#9ad54fb6-cb3c-420d-947d-0e1bdb21cf61http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#9ad54fb6-cb3c-420d-947d-0e1bdb21cf61skullfirehttp://social.msdn.microsoft.com/Profile/en-US/?user=skullfireSQLDataReader.GetOrdinal() fails rarely with IndexOutOfRangeI am having the exact same problem. I'm using ASP .Net 2.0 and SQL Server 2000. I have no idea what can be causing this issue, but I would like to get information about what can I do to solve it! This is a critical error on the enterprise application, and it's not happening A LOT.<br>Thanks,<br>skullfire<br>Tue, 16 Jan 2007 23:34:46 Z2007-01-16T23:34:46Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#fe78a6a4-267a-4d5e-8873-b18ca0bd6bcchttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#fe78a6a4-267a-4d5e-8873-b18ca0bd6bccShameer A Uhttp://social.msdn.microsoft.com/Profile/en-US/?user=Shameer%20A%20USQLDataReader.GetOrdinal() fails rarely with IndexOutOfRange<p>HI,</p> <p>I had the same problem but fortunately it is fixed now. The issue was with one of the .nettiers settings (My application uses codesmith generated code using .nettiers templates for .NET 2.0). When code is generated, codesmith creates a <em>procedures.resources</em> file which is embedded into the application assemby by default. Then .nettires uses a setting in it's configuration file (<em>UseStoredprocedure=&quot;true | false&quot;) </em>to execute the stored procedures from the database or read the procedure from <em>procedure.resources </em>file and execute it. So if the above setting is 'false' (which is by default), .nettiers reads the sprocs from assembly (which may not be the latested updated one). Changing the setting to 'true' fixed the error. But this still does not explain why the application was working most of the time and fails only intermittently.</p> <p>Regards</p> <p>Shameer</p> <p> </p> <p> </p>Sat, 20 Jan 2007 09:05:20 Z2007-01-20T09:05:20Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#bb4f1d4e-573d-4bfe-8d0c-13884e7a7499http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#bb4f1d4e-573d-4bfe-8d0c-13884e7a7499Zahirhttp://social.msdn.microsoft.com/Profile/en-US/?user=ZahirSQLDataReader.GetOrdinal() fails rarely with IndexOutOfRange<p>Hi,</p> <p>Did you get  a chance to contact Microsoft Support to resolve this, if so please let me know if you have any updates. Some time back we called the Microsoft premier support but did not get any resolution they simply blamed our code, but it works well most of the time. The only time it seems to happen is when the server load is high. You can reach me at zahirhas at hotmail dot com for more info.</p> <p>Thanks,</p> <p>Zahir</p>Mon, 22 Jan 2007 22:34:26 Z2007-01-22T22:34:26Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#a4597356-6796-4457-8735-8ef96245dbdehttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#a4597356-6796-4457-8735-8ef96245dbdeZahirhttp://social.msdn.microsoft.com/Profile/en-US/?user=ZahirSQLDataReader.GetOrdinal() fails rarely with IndexOutOfRangeI believe this is ADO.NET related and nothing to do specifically with .nettires. But please keep us updated if you find anything resolves this issue.Mon, 22 Jan 2007 22:36:30 Z2007-01-22T22:36:30Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#b4e45e71-168c-4e1b-b6ee-5530bcf167bbhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#b4e45e71-168c-4e1b-b6ee-5530bcf167bbPatch79http://social.msdn.microsoft.com/Profile/en-US/?user=Patch79SQLDataReader.GetOrdinal() fails rarely with IndexOutOfRange<p>Dear all</p> <p>We are getting this error too. It is totally random, although turning connection pooling off reduces the frequency of the error. We are using SQL Server 2005 and ASP.net 1.1. Frequency seems to increase with load - we are convinced it is an ADO bug.  Have any of you had a response from Microsoft or have found a solution?</p> <p>Regards</p> <p>Phil</p>Mon, 26 Feb 2007 10:06:52 Z2007-02-26T10:06:52Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#f9476392-ae5f-46bf-93f8-46a7deaca08fhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#f9476392-ae5f-46bf-93f8-46a7deaca08fPatch79http://social.msdn.microsoft.com/Profile/en-US/?user=Patch79SQLDataReader.GetOrdinal() fails rarely with IndexOutOfRange<p>OK - think we've cracked it..</p> <p>Our ASP.net v1.1 code was originally using the Data Access Application Block to access our SQL Server. We've replaced this and now we manually create connection, command and dataset objects and the problem seems to have resolved itself. Not sure if you guys were/are using the code block but it seems that it is that which is causing the problem.</p> <p>Comments please.</p> <p>Phil</p>Tue, 27 Feb 2007 12:19:25 Z2007-02-27T12:19:25Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#053c2932-4409-4a2b-89c1-0821fa69a889http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#053c2932-4409-4a2b-89c1-0821fa69a889DRDandlehttp://social.msdn.microsoft.com/Profile/en-US/?user=DRDandleSQLDataReader.GetOrdinal() fails rarely with IndexOutOfRange<p>Hi,</p> <p>The problem I am having is very similar although I don't get an IndexOutOfRange error.  I get the following call stack:</p> <p>   at System.Data.ProviderBase.FieldNameLookup.GetOrdinal(String fieldName)<br>   at System.Data.SqlClient.SqlDataReader.GetOrdinal(String name)<br>   at GTS.ComAppLibrary.LXRecord.ReadRecords(SqlDataReader _dr)</p> <p> </p> <p>The error does not happen all the time.  The code that uses the GetOrdinal is part of a service written in the 2.0 framework.  The service loops ever couple seconds.  It is very hard to track down because this application is distributed to our customers and I can't get the problem to happen in my test environment.</p> <p>We are not using application blocks for data access.  We are using:</p><font color="#2b91af" size=2> <p>SqlConnection</font> and <font color="#2b91af" size=2>SqlCommand</font></p> <p>My work around at this point is to make my own enums for the ordinals, but this is a pain and I can't understand why this problem is still going on.  This thread goes on for 2 years!</p> <p>It seems the only thing in common is using ado.net and maybe it is worse under load and that is why it is so hard to reproduce.</p> <p> </p> <p>Has MS responded?  Should I create a new thread?</p> <p> </p> <p>Thanks</p> <p> </p> <p>Randy</p></font>Thu, 01 Mar 2007 15:46:00 Z2007-03-01T15:46:00Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#d80de829-d0bd-4732-b857-10c7cd7722fchttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#d80de829-d0bd-4732-b857-10c7cd7722fcZahirhttp://social.msdn.microsoft.com/Profile/en-US/?user=ZahirSQLDataReader.GetOrdinal() fails rarely with IndexOutOfRange<P>We also using Data Application Block. We come up with the following workaround after that, the&nbsp;error not yet happened for the past two weeks.</P><FONT face=Helv size=2> <P>If you are running out of process on your website you should be able to set the Application Pool Recycling to recycle every 15 minutes. This has helped us avoid the GetOrdinal error however now we are receiving occasional web erros when the recycle process forces a shutdown. Please post your experiences with this configuration change.</P> <P>Thanks,</P> <P>Zahir</P></FONT>Wed, 14 Mar 2007 20:51:08 Z2007-03-14T20:51:08Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#434b4a31-2dfb-4c71-9fdb-44a02732c5aahttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#434b4a31-2dfb-4c71-9fdb-44a02732c5aaZyadhttp://social.msdn.microsoft.com/Profile/en-US/?user=ZyadSQLDataReader.GetOrdinal() fails rarely with IndexOutOfRangeHas any solution been found on this matter, as I am experiencing the same exact problem.<br>Sat, 31 Mar 2007 16:35:21 Z2007-03-31T16:35:21Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#1731bea5-1410-465d-89e3-5d2df91c38f2http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#1731bea5-1410-465d-89e3-5d2df91c38f2Zyadhttp://social.msdn.microsoft.com/Profile/en-US/?user=ZyadSQLDataReader.GetOrdinal() fails rarely with IndexOutOfRangeJust to let you guys know that I've solved the problem.<br><br>The problem was that my dataAccess connections and methods were defined as STATIC, which means that sometimes the datareader was receiving data from other tables.<br><br>I changed that and everything is now ok.<br>Mon, 02 Apr 2007 16:39:07 Z2007-04-02T16:39:07Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#13ffbd53-c67f-42f3-9951-507827199488http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#13ffbd53-c67f-42f3-9951-507827199488Lee Murawski _o2http://social.msdn.microsoft.com/Profile/en-US/?user=Lee%20Murawski%20_o2SQLDataReader.GetOrdinal() fails rarely with IndexOutOfRange<p> <div class=quote> <table width="85%"> <tbody> <tr> <td class=txt4> <strong>Zyad wrote:</strong></td></tr> <tr> <td class=quoteTable> <table width="100%"> <tbody> <tr> <td class=txt4 valign=top width="100%">Just to let you guys know that I've solved the problem.<br><br>The problem was that my dataAccess connections and methods were defined as STATIC, which means that sometimes the datareader was receiving data from other tables.<br><br>I changed that and everything is now ok.<br></td></tr></tbody></table></td></tr></tbody></table></div> <p></p> <p> </p> <p>Can you explain what you mean as STATIC?  And how you changed your code to fix this issue?</p> <p> </p> <p>Thanks</p>Tue, 03 Apr 2007 20:07:47 Z2007-04-03T20:07:47Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#4676f0c2-8ed9-4670-8b27-875b2afe940fhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#4676f0c2-8ed9-4670-8b27-875b2afe940fZyadhttp://social.msdn.microsoft.com/Profile/en-US/?user=ZyadSQLDataReader.GetOrdinal() fails rarely with IndexOutOfRange<p>Sorry that did not solve my problem.</p> <p>It started re-appearing after a couple of days.</p> <p> </p> <p>It seems that this happens in 2 cases : (but it's so hard to be able to really pin point the problem)</p> <p> </p> <p>1. When there's a peak on the server</p> <p>2. When there's a connection timeout with the database.</p> <p> </p> <p>But that problem is very strange, as it started to appear when I migrated my application from 1.1 to 2.0.  </p> <p> </p> <p>Anyone from Microsoft can help ?</p>Thu, 12 Apr 2007 14:17:21 Z2007-04-12T14:17:21Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#4f74995c-3159-4892-9884-aa0e3421d9b8http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#4f74995c-3159-4892-9884-aa0e3421d9b8Lee Murawski _o2http://social.msdn.microsoft.com/Profile/en-US/?user=Lee%20Murawski%20_o2SQLDataReader.GetOrdinal() fails rarely with IndexOutOfRange<p>That's my exact experience as well.</p> <p> </p> <p>It appears to me that there is a &quot;bad&quot; connection in the connection pool.  Due to the &quot;timeout&quot; error, my normal connection closing  routine is bypassed.  Once this happens, other functions try to use this function.  If you are referencing a column by name, you get the IndexOutOfRange error.  If you are referencing by index, you will get typically get a type conversion error.</p> <p> </p> <p>I just migrated all my code from ASP/VB6 to asp.net 2.0.</p> <p> </p> <p>If I were to guess, the connection that had the timeout is made available to the pool again but is still actively running the query that timed out.  I know my code doesn't close the connection when the error occurs.  I try to explicitly close every connection in my application when the transaction is complete.  The only time this doesn't happen is with errors at this time.</p> <p> </p>Thu, 12 Apr 2007 14:51:26 Z2007-04-12T14:51:26Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#3165bed0-f01b-479a-b758-8eb6b7016d6chttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#3165bed0-f01b-479a-b758-8eb6b7016d6cCommonGenius.comhttp://social.msdn.microsoft.com/Profile/en-US/?user=CommonGenius.comSQLDataReader.GetOrdinal() fails rarely with IndexOutOfRangeYou should use exception handling to ensure your connection is closed even if there is a timeout or other error. However, I seriously doubt that the connection is being returned to the pool while still actively running a query. Not to mention that I timeout would immediately kill the query.Thu, 12 Apr 2007 15:30:23 Z2007-04-12T15:30:23Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#1d2e5540-173c-4196-8875-c1aaaddb8e4fhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#1d2e5540-173c-4196-8875-c1aaaddb8e4fPatch79http://social.msdn.microsoft.com/Profile/en-US/?user=Patch79SQLDataReader.GetOrdinal() fails rarely with IndexOutOfRange<p>The only way we could prevent this error was to turn connection pooling off.  Not a great idea in itself but not a problem for us as we have a limited user base and restart our application out of working hours.  We are convinced it is a pooling problem.</p>Thu, 12 Apr 2007 15:41:41 Z2007-04-12T15:41:41Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#4f53c5f2-dceb-4495-a9f1-7a8070118e98http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#4f53c5f2-dceb-4495-a9f1-7a8070118e98Lee Murawski _o2http://social.msdn.microsoft.com/Profile/en-US/?user=Lee%20Murawski%20_o2SQLDataReader.GetOrdinal() fails rarely with IndexOutOfRange<p>I plan to add the exception handling in the next round of updates to the webapp.  During the conversion I disabled all the &quot;on error&quot; routines (good old vb) to capture all small conversion issues.  It's a daunting task since I will have to touch almost every bit of code.</p> <p> </p> <p>But it's hard to explain the crossed data and invalid recordsets otherwise.  How does my code run rs.executereader, then iterate the resultset and not find the columns?</p> <p> </p> <p> </p>Thu, 12 Apr 2007 15:43:47 Z2007-04-12T15:43:47Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#a4f8fc98-3ae6-4e7d-ba69-48cdd4d0ff42http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#a4f8fc98-3ae6-4e7d-ba69-48cdd4d0ff42Patch79http://social.msdn.microsoft.com/Profile/en-US/?user=Patch79SQLDataReader.GetOrdinal() fails rarely with IndexOutOfRangePlease, please first disable connection pooling and see if that resolves your issue.  If it does and and we can get more to collaborate this then maybe someone from Microsoft will start to look into it.Thu, 12 Apr 2007 15:49:41 Z2007-04-12T15:49:41Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#3c80e024-e3a8-4413-976b-118f949da351http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#3c80e024-e3a8-4413-976b-118f949da351Lee Murawski _o2http://social.msdn.microsoft.com/Profile/en-US/?user=Lee%20Murawski%20_o2SQLDataReader.GetOrdinal() fails rarely with IndexOutOfRange<p>I have turned off connection pooling.</p> <p> </p> <p>Back in a few day to post my observations.</p>Thu, 12 Apr 2007 18:36:10 Z2007-04-12T18:36:10Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#e204678f-9c08-4f31-9660-cf3ee7b96deahttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#e204678f-9c08-4f31-9660-cf3ee7b96deaShaun Walker1http://social.msdn.microsoft.com/Profile/en-US/?user=Shaun%20Walker1SQLDataReader.GetOrdinal() fails rarely with IndexOutOfRangeWe are experiencing this exact same problem very frequently lately. The error gets logged in our our event viewer and always identifies a column which is the first column expected from the DataReader. This leads me to believe that the row is empty in the DataReader. However in reviewing the code we are using standard if dr.read() then ... logic prior to referencing the DataReader column values. Other specifics of our environment are we using SQL Server 2005 ( a recent migration ) and a single IIS 6.0 website instance which is handling 8.5+ million requests per month ( so relatively heavy load ). I never expected that using dr.HasRows was a firm requirement to using DataReaders in ADO.NET ( especially since it did not exist in ADO.NET 1.0 ) - but it looks like this is the only reasonable advice offered so far on this topic.Thu, 12 Apr 2007 23:15:55 Z2007-04-12T23:15:55Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#015d5a22-a114-4ec7-a548-52b6783e8355http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#015d5a22-a114-4ec7-a548-52b6783e8355Lee Murawski _o2http://social.msdn.microsoft.com/Profile/en-US/?user=Lee%20Murawski%20_o2SQLDataReader.GetOrdinal() fails rarely with IndexOutOfRange<div class=quote> <table width="85%"> <tbody> <tr> <td class=txt4> <strong>Lee wrote:</strong></td></tr> <tr> <td class=quoteTable> <table width="100%"> <tbody> <tr> <td class=txt4 valign=top width="100%"> <p>I have turned off connection pooling.</p> <p> </p> <p>Back in a few day to post my observations.</p> <p></p></td></tr></tbody></table></td></tr></tbody></table></div> <p></p> <p> </p> <p>Day one with connection pooling off, these errors have not occurred.</p>Fri, 13 Apr 2007 15:43:01 Z2007-04-13T15:43:01Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#143a147d-ba5d-4de9-86e2-141d918b9d90http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#143a147d-ba5d-4de9-86e2-141d918b9d90Patch79http://social.msdn.microsoft.com/Profile/en-US/?user=Patch79SQLDataReader.GetOrdinal() fails rarely with IndexOutOfRangehmm.. interesting, please give it a few more days tho just be sure.. incidentally are you using the DAAB?Fri, 13 Apr 2007 15:48:31 Z2007-04-13T15:48:31Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#ff217f6f-c693-4d4f-b07e-b7ac48a69bbdhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#ff217f6f-c693-4d4f-b07e-b7ac48a69bbdLee Murawski _o2http://social.msdn.microsoft.com/Profile/en-US/?user=Lee%20Murawski%20_o2SQLDataReader.GetOrdinal() fails rarely with IndexOutOfRange<p> <div class=quote> <table width="85%"> <tbody> <tr> <td class=txt4> <strong>Patch79 wrote:</strong></td></tr> <tr> <td class=quoteTable> <table width="100%"> <tbody> <tr> <td class=txt4 valign=top width="100%">hmm.. interesting, please give it a few more days tho just be sure.. incidentally are you using the DAAB?</td></tr></tbody></table></td></tr></tbody></table></div> <p></p> <p> </p> <p>I'm not familiar with DAAB.</p>Fri, 13 Apr 2007 16:25:07 Z2007-04-13T16:25:07Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#a1b50fd6-6465-48f5-9f16-adbc627184eahttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#a1b50fd6-6465-48f5-9f16-adbc627184eaShaun Walker1http://social.msdn.microsoft.com/Profile/en-US/?user=Shaun%20Walker1SQLDataReader.GetOrdinal() fails rarely with IndexOutOfRangeYes we are using MSDAAB. And turning off connection pooling is a no-go for our site - given the amount of traffic  we are supporting.Fri, 13 Apr 2007 20:55:32 Z2007-04-13T20:55:32Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#6f65f3a7-8b4e-4da4-a641-57f24dbcc3abhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#6f65f3a7-8b4e-4da4-a641-57f24dbcc3abZyadhttp://social.msdn.microsoft.com/Profile/en-US/?user=ZyadSQLDataReader.GetOrdinal() fails rarely with IndexOutOfRange<p>I've turned pooling off.</p> <p>It's been 3 days now, and I haven't had a single error.</p> <p> </p> <p>However, turning pooling off, is not something that is recommended.  There must be something else going on that is causing the connections to act this way.</p>Sat, 14 Apr 2007 05:25:08 Z2007-04-14T05:25:08Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#93220790-ee16-4a82-a2d4-d45b31a8915chttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#93220790-ee16-4a82-a2d4-d45b31a8915cLee Murawski _o2http://social.msdn.microsoft.com/Profile/en-US/?user=Lee%20Murawski%20_o2SQLDataReader.GetOrdinal() fails rarely with IndexOutOfRange<p>I haven't had this error since I turned off connection pooling.</p> <p> </p> <p>I can't say I've been as fortunate as Zyad with no errors though.  But these errors are my fault.  =)</p>Mon, 16 Apr 2007 09:18:36 Z2007-04-16T09:18:36Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#9a8ad407-0b96-4cf2-a975-3ec6f3314df6http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#9a8ad407-0b96-4cf2-a975-3ec6f3314df6William Vaughnhttp://social.msdn.microsoft.com/Profile/en-US/?user=William%20VaughnSQLDataReader.GetOrdinal() fails rarely with IndexOutOfRangeTypically, an out of range failure is because the object being refrenced is not populated with data. For example when your routine to fetch the DataReader fails to return any rows. This might be because there are no rows to fetch (thus HasRows is essential) but it could be that the routine failed, trapped the exception and returned without indicating an exception to the calling routine. If turning off the Connection pool fixes it, I suspect faulty exception handlers somewhere down the call chain. For those that have tried turning off the pool, check to see if the number of connections being orphaned at the server has increased... I expect they have. If this is the case, you've delayed the inevitable failure of the server to accept additional connections.Wed, 18 Apr 2007 20:48:33 Z2007-04-18T20:48:33Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#909eb888-a7e3-4cf5-b015-7e51f8f8f156http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#909eb888-a7e3-4cf5-b015-7e51f8f8f156Lee Murawski _o2http://social.msdn.microsoft.com/Profile/en-US/?user=Lee%20Murawski%20_o2SQLDataReader.GetOrdinal() fails rarely with IndexOutOfRange<p> <div class=quote> <table width="85%"> <tbody> <tr> <td class=txt4> <strong>William Vaughn wrote:</strong></td></tr> <tr> <td class=quoteTable> <table width="100%"> <tbody> <tr> <td class=txt4 valign=top width="100%">Typically, an out of range failure is because the object being refrenced is not populated with data.</td></tr></tbody></table></td></tr></tbody></table></div> <p></p> <p> </p> <p>When my code referenced the data reader by index, I would get type conversion errors rather than index out of range errors.  Whatever corrupted the connection has already happened at this point.</p> <p> </p> <p>Example one:</p> <blockquote dir=ltr style="margin-right:0px"><font size=2> <p>The error description is as follows: System.Web.HttpUnhandledException: Exception of type 'System.Web.HttpUnhandledException' was thrown. ---&gt; System.IndexOutOfRangeException: theValue</p> <p>at System.Data.ProviderBase.FieldNameLookup.GetOrdinal(String fieldName)</p> <p>at System.Data.SqlClient.SqlDataReader.GetOrdinal(String name)</p> <p>at System.Data.SqlClient.SqlDataReader.get_Item(String name)</p> <p>at o2busRegRead.GetSetting(String sKeyName, String sValueName) in D:\webfiles\oxygen\App_Code\RegRead.vb:line 90</p></font> <p> </p> <p>The code:</p> <p dir=ltr>Dim rs As SqlDataReader = c.ExecuteReader</p> <p dir=ltr>If rs.Read = True Then<br>     theValue = rs(&quot;theValue&quot;)<br>  Else<br>     theValue = &quot;&quot;<br>  End If</p></div> <p>Example two:</p><font size=2> <blockquote dir=ltr style="margin-right:0px"> <p>The error description is as follows: System.Web.HttpUnhandledException: Exception of type 'System.Web.HttpUnhandledException' was thrown. ---&gt; System.InvalidCastException: Unable to cast object of type 'System.Int32' to type 'System.String'.</p> <p>at System.Data.SqlClient.SqlBuffer.get_String()</p> <p>at System.Data.SqlClient.SqlDataReader.GetString(Int32 i)</p> <p>at o2busOrder.GetNotes() in D:\webfiles\oxygen\App_Code\order.vb:line 704</p> <p> </p> <p>The code:</p> <p> </p> <p>        Dim rs As SqlDataReader = c.ExecuteReader</p> <p>        sNote = &quot;&quot;<br>        While rs.Read = True<br>            sNote = sNote &amp; rs(0)<br>        End While<br></p></div> <p></font> <div class=quote> <table width="85%"> <tbody> <tr> <td class=txt4> <strong>William Vaughn wrote:</strong></td></tr> <tr> <td class=quoteTable> <table width="100%"> <tbody> <tr> <td class=txt4 valign=top width="100%"> For example when your routine to fetch the DataReader fails to return any rows. This might be because there are no rows to fetch (thus HasRows is essential) but it could be that the routine failed, trapped the exception and returned without indicating an exception to the calling routine. If turning off the Connection pool fixes it, I suspect faulty exception handlers somewhere down the call chain. For those that have tried turning off the pool, check to see if the number of connections being orphaned at the server has increased... I expect they have. If this is the case, you've delayed the inevitable failure of the server to accept additional connections.</td></tr></tbody></table></td></tr></tbody></table></div> <p></p> <p> </p> <p>But if the connection is not properly closed, shouldn't an unused connection be selected from the pool when the next .Open is done?  And eventually you should run out of connections in the pool, this would support the theory of having orphan connections with pooling off as well.</p> <p> </p> <p>6 days without this error with connection pooling off.</p>Thu, 19 Apr 2007 05:30:54 Z2007-04-19T05:30:54Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#69c99dc6-6041-4d69-8229-ba6e0be3f5d2http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#69c99dc6-6041-4d69-8229-ba6e0be3f5d2Lee Murawski _o2http://social.msdn.microsoft.com/Profile/en-US/?user=Lee%20Murawski%20_o2SQLDataReader.GetOrdinal() fails rarely with IndexOutOfRangeStill going.Tue, 08 May 2007 16:18:18 Z2007-05-08T16:18:18Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#3eefdb2b-b630-4d3a-b072-d43811f5d9e7http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#3eefdb2b-b630-4d3a-b072-d43811f5d9e7Emanuele2http://social.msdn.microsoft.com/Profile/en-US/?user=Emanuele2SQLDataReader.GetOrdinal() fails rarely with IndexOutOfRange<p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:10pt;color:black;font-family:Arial">Hi everybody,<br style=""><br style=""></span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:10pt;color:black;font-family:Arial">I think I’m experiencing your same problem</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:10pt;color:black;font-family:Arial"><br>We developed a lot of WebApplications and our environment is on .NET 2.0 and Sql Server 200o. (All Service packs are always installed)</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:10pt;color:black;font-family:Arial"><span style=""> </span></span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:10pt;color:black;font-family:Arial">Most of time (99%) everything is running well, but sometimes (when exactly, we don't know) the same Web Applications that worked 1000 times, fail.</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:10pt;color:black;font-family:Arial"> </span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:10pt;color:black;font-family:Arial">It seems sp doesn't return right fields or something similar. </span><span style="font-size:10pt;font-family:Arial">This happens occasionally and, when it occurs, a lot of components have the same problem.</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:10pt;color:black;font-family:Arial"> </span></p> <p style="text-indent:0in"><span style="font-size:10pt">In Event Viewer Warning appear messages like: </span></p> <p style="text-indent:0in"><span style="font-size:10pt"> </span></p> <p style="text-indent:0in"><span style="font-size:10pt">System.IndexOutOfRangeException: Site_Uid at System.Data.ProviderBase.FieldNameLookup.GetOrdinal(String fieldName) at System.Data.SqlClient.SqlDataReader.GetOrdinal(String name) at USNext.CommonUserControls.ContactInfo.GetLoginSites(SqlConnection sqlCnn)</span></p> <p style="text-indent:0in"><span style="font-size:10pt"> </span></p> <p style="text-indent:0in"><span style="font-size:10pt">DataBinding: 'System.Data.Common.DbDataRecord' does not contain a property with the name 'name'. </span></p> <p style="text-indent:0in"><span style="font-size:10pt"> </span></p> <p style="text-indent:0in"><span style="font-size:10pt;color:black">I’m pretty sure that the code and the stored procedure are fine also because they are old and executed a lot of times (more than 10000) every day. </span></p> <p style="text-indent:0in"><span style="font-size:10pt;color:black"> </span></p> <p style="text-indent:0in"><span style="font-size:10pt;color:black">We started to have this type of problem a couple of months ago, initially sometime then every day around same hour (during the morning, when the server ). </span></p> <p style="text-indent:0in"><span style="font-size:10pt;color:black"> </span></p> <p style="text-indent:0in"><span style="font-size:10pt;color:black">One month ago I increased the Max Pool Size setting of connection string to 500 and now it happens one time every 7-10 days. When it occurs I check the connections opened on SQL and they are not a lot. <span style=""> </span></span></p> <p style="text-indent:0in"><span style="font-size:10pt;color:black"> </span></p> <p style="text-indent:0in"><span style="font-size:10pt;color:black">Now I followed also all Alazela suggestions to track what exactly occurs but I can’t turn off connection pooling given the amount of traffic we are supporting.</span></p> <p style="text-indent:0in"><span style="font-size:10pt;color:black"> </span></p> <p style="text-indent:0in"><span style="font-size:10pt;color:black">The only solution I found:</span></p> <p style="text-indent:0in"><span style="font-size:10pt;color:black"><span style=""> </span>- Wait a few minutes then everything return to work fine</span></p> <p style="text-indent:0in"><span style="font-size:10pt;color:black"><span style=""> </span>- Restart IIS<span style="">   </span></span></p> <p style="text-indent:0in"><span style="font-size:10pt;color:black"> </span></p> <p style="text-indent:0in"><span style="font-size:10pt;color:black">Does someone know how to solve this problem? This post has been opened in Nov 2005 …</span></p> <p style="text-indent:0in"><span style="font-size:10pt;color:black"> </span></p> <p style="text-indent:0in"><span style="font-size:10pt;color:black">Thanks,</span></p> <p style="text-indent:0in"><span style="font-size:10pt;color:black">Emanuele</span></p>Thu, 10 May 2007 17:26:46 Z2007-05-10T17:26:46Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#fed50888-3627-42e8-a146-bb1c06e68b0dhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#fed50888-3627-42e8-a146-bb1c06e68b0dEmanuele2http://social.msdn.microsoft.com/Profile/en-US/?user=Emanuele2SQLDataReader.GetOrdinal() fails rarely with IndexOutOfRange<span>  <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:10pt;color:black;font-family:Arial">I tracked it.<br><br></span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:10pt;color:black;font-family:Arial">This is my Code:</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:10pt;color:black;font-family:Arial"> </span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'">private void GetLoginSites(SqlConnection sqlCnn)</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'">{</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"><span>  </span>SqlDataReader rs = null;</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"><span>  </span>string __TempDebugMessage = &quot;&quot;;</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"> </span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"><span>  </span>try </span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"><span>  </span>{</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"> </span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"><span>    </span>// Create Command</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"><span>    </span>__TempDebugMessage += &quot;1&quot;;</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"><span>    </span>SqlCommand sqlCmd<span> </span>= new SqlCommand();</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"><span>   </span><span> </span>sqlCmd.Connection = sqlCnn;<span>                 </span></span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"><span>    </span>sqlCmd.CommandType = CommandType.StoredProcedure;</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"><span>    </span>sqlCmd.CommandText = &quot;Retrieve_Login_Sites&quot;;</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"> </span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"><span>    </span>// Set Parameters</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"><span>    </span>__TempDebugMessage += &quot;-2&quot;;</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"><span>    </span>sqlCmd.Parameters.Clear() ;<span>  </span></span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"> </span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"><span>    </span>__TempDebugMessage += &quot;-3&quot;;</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"><span>    </span>SqlParameter ContactUidParam = sqlCmd.CreateParameter();</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"><span>    </span>ContactUidParam.Direction = ParameterDirection.Input;</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"><span>    </span>ContactUidParam.ParameterName =&quot;@LoginUid&quot;;</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"><span>    </span>ContactUidParam.Value = this._LoginUid.ToString();</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"><span>    </span>ContactUidParam.SqlDbType = SqlDbType.Int; </span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"><span>    </span>sqlCmd.Parameters.Add(ContactUidParam);<span>   </span></span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"> </span><span style="font-size:8pt;color:black;font-family:'Courier New'"> </span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"><span>    </span>__TempDebugMessage += &quot;&lt;br&gt;&quot;;</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"><span>    </span>__TempDebugMessage += &quot;EXEC Retrieve_Login_Sites &quot;+this._LoginUid.ToString();</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"> </span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"></span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"><span>    </span>this._SitesDOM = new XmlDocument();</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"><span>    this._</span>SitesDOM.AppendChild(this._SitesDOM.CreateElement(&quot;SITES&quot;));</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"> </span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"><span>    </span>// Execute Reader</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"><span>    </span>__TempDebugMessage += &quot;ExecuteReader&lt;br&gt;&lt;br&gt;&quot;;</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"><span>    </span>rs = sqlCmd.ExecuteReader(); </span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"> </span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"><span>    </span>// Load DataReader Main Info</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"><span>    </span>__TempDebugMessage += &quot;FieldCount: &quot; + rs.FieldCount.ToString() + &quot;&lt;br&gt;&quot;;</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"><span>    </span>__TempDebugMessage += &quot;HasRows: &quot; + rs.HasRows.ToString() + &quot;&lt;br&gt;&quot;;</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"> </span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"><span>    </span>// Load Schema Table</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"><span>    </span>DataTable __rsDT = rs.GetSchemaTable();</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"><span>    </span>__TempDebugMessage += &quot;CaseSensitive: &quot; + __rsDT.CaseSensitive.ToString() + &quot;&lt;br&gt;&quot;;</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"><span>    </span>__TempDebugMessage += &quot;HasErrors:<span>     </span>&quot; + __rsDT.HasErrors.ToString() + &quot;&lt;br&gt;&lt;br&gt;&quot;;</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"> </span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"><span>    </span>// Load Columns</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"><span>    </span>__TempDebugMessage += &quot;FIELDS:&lt;br&gt;&quot;;</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"><span>    </span>for(int __CCounter=0; __CCounter&lt;rs.FieldCount; __CCounter++)</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"><span>    </span>{</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"><span>      </span>__TempDebugMessage += __CCounter.ToString() + &quot; &quot; + rs.GetName(__CCounter) + &quot; [&quot;;</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"><span>      </span>__TempDebugMessage += rs.GetFieldType(__CCounter).ToString();</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"><span>      </span>__TempDebugMessage += &quot; - &quot; + rs.GetDataTypeName(__CCounter) + &quot;]&lt;br&gt;&quot;;</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"><span>    </span>}</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"><span>    </span>__TempDebugMessage += &quot;&lt;br&gt;&quot;;</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"> </span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"><span>    </span>int __CReadCount = 0;</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"><span>    </span>__TempDebugMessage += &quot;ROWS:&lt;br&gt;&quot;;</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"><span>    </span>while(rs.Read())</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"><span>    </span>{</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"><span>      </span>try</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"><span>      </span>{</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"><span>        </span>__CReadCount += 1;</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"><span>        </span>__TempDebugMessage += __CReadCount.ToString() + &quot; &quot;;</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"> </span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"><span>        </span>int SiteUid = rs.GetInt32(rs.GetOrdinal(&quot;Site_Uid&quot;));</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"><span>        </span>__TempDebugMessage += &quot;A&quot;;</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"><span>                                         </span></span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"><span>   </span><span>     </span>string SiteName = rs.GetString(rs.GetOrdinal(&quot;Site_Display_Name&quot;));</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"><span>        </span>__TempDebugMessage += &quot;B&quot;;</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"><span>                                         </span></span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"><span>        </span>string SiteServer = rs.GetString(rs.GetOrdinal(&quot;Site_Web_Server&quot;));</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"><span>        </span>__TempDebugMessage += &quot;C&quot;;</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"><span>                                         </span></span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"><span>        </span>XmlElement SiteElement = this._SitesDOM.CreateElement(&quot;SITE&quot;);</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"><span>        </span>SiteElement.Attributes.Append(this._SitesDOM.CreateAttribute(&quot;uid&quot;));</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"><span>        </span>SiteElement.Attributes[&quot;uid&quot;].Value = SiteUid.ToString();</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"><span>        </span>SiteElement.Attributes.Append(this._SitesDOM.CreateAttribute(&quot;name&quot;));</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"><span>        </span>SiteElement.Attributes[&quot;name&quot;].Value = SiteName;</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"><span>        </span>SiteElement.Attributes.Append(this._SitesDOM.CreateAttribute(&quot;web_url&quot;));</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"><span>        </span>SiteElement.Attributes[&quot;web_url&quot;].Value = SiteServer;</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"><span>        </span>this._SitesDOM.DocumentElement.AppendChild(SiteElement);</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"><span>        </span>__TempDebugMessage += &quot;D&lt;BR&gt;&quot;;</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"> </span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"><span>      </span>}</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"><span>      </span>catch(Exception exSP)</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"><span>      </span>{</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"><span>        </span>this._ClassError=&quot;GLS1 - &quot; + exSP.Message; </span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"><span>        </span>this._ClassErrorString=exSP.ToString() + &quot;&lt;br&gt;&lt;br&gt;&quot; + __TempDebugMessage; </span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"><span>      </span>}</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"><span>    </span>}</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"><span>                           </span></span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"><span>  </span>}</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"><span>  </span>catch (Exception ex)</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"><span>  </span>{</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"><span>    </span>this._ClassError=&quot;GLS2 - &quot; + ex.Message; </span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"><span>    </span>this._ClassErrorString=ex.ToString() + &quot;&lt;br&gt;&lt;br&gt;&quot; + __TempDebugMessage; </span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"><span>  </span>}</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"><span>  </span>finally</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"><span>  </span>{</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"><span>    </span>if(rs!=null)<span>  </span></span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"><span>      </span>rs.Close();</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"><span>  </span>}</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"> </span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'">}</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:10pt;color:black;font-family:Arial"> </span></p><span style="font-size:10pt;color:black;font-family:Arial"><br style="page-break-before:always" clear=all></span> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:10pt;color:black;font-family:Arial">This method went in error and information wrote in debug message are:</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"> </span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'">GLS01 – Site_Uid</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"> </span></p> <p style="text-indent:0in"><span style="font-size:8pt;font-family:'Courier New'">System.IndexOutOfRangeException: Site_Uid at System.Data.ProviderBase.FieldNameLookup.GetOrdinal(String fieldName) at System.Data.SqlClient.SqlDataReader.GetOrdinal(String name) at USNext.CommonUserControls.ContactInfo.GetLoginSites(SqlConnection sqlCnn)</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"> </span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'">1-2-3</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'">Retrieve_Login_Sites 27, 0, 1</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'">Execute Reader</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"> </span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'">Field Count: 2</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'">HasRows: True</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'">CaseSensitive: False</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'">HasErrors: False</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"> </span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'">FIELDS:</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'">0 List_Uid [int]</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'">1 Sequence [int]</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"> </span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'">ROWS:</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'">1 2 3</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:8pt;color:black;font-family:'Courier New'"> </span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:10pt;color:black;font-family:Arial">Stored Procedure Retrieve_Login_Sites gives me back following fields </span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:10pt;font-family:Arial">Site_Uid<span style="color:gray">, </span>Site_Display_Name<span style="color:gray">, </span>Site_Web_Server<span style="color:gray"></span></span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:10pt;color:black;font-family:Arial"> </span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:10pt;color:black;font-family:Arial">Buy not now. Now I received a result set of another SQLCommand with following fields: List_Uid, Sequence.</span><span style="font-size:10pt;font-family:Arial"></span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:10pt;color:black;font-family:Arial"> </span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:10pt;color:black;font-family:Arial">This is not the only error we had during the problem.</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:10pt;color:black;font-family:Arial">Can it be useful to Microsoft? </span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:10pt;color:black;font-family:Arial"> </span></p> <p style="text-indent:0in"><span style="font-size:10pt;color:black">Thanks,</span></p> <p style="text-indent:0in"><span style="font-size:10pt;color:black">Emanuele</span></p></span>Fri, 11 May 2007 15:20:38 Z2007-05-11T15:20:38Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#faa0aa0f-6cd1-4a9d-a388-1953fd888875http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#faa0aa0f-6cd1-4a9d-a388-1953fd888875Lee Murawski _o2http://social.msdn.microsoft.com/Profile/en-US/?user=Lee%20Murawski%20_o2SQLDataReader.GetOrdinal() fails rarely with IndexOutOfRange<p>I would add a connection close to your exception logic and see if that resolved your issue.</p> <p> </p> <p>Do you get any other errors before this error starts to happen?  Maybe a timeout error ?</p> <p> </p> <p> </p>Fri, 11 May 2007 15:51:59 Z2007-05-11T15:51:59Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#36a60786-6c2c-4a65-8d93-39a682e4ba08http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#36a60786-6c2c-4a65-8d93-39a682e4ba08Emanuele2http://social.msdn.microsoft.com/Profile/en-US/?user=Emanuele2SQLDataReader.GetOrdinal() fails rarely with IndexOutOfRange<p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:10pt;font-family:Arial">Hi Lee,</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:10pt;font-family:Arial"> </span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:10pt;font-family:Arial">Thanks for your attention but connection it's opened and closed by caller method and also if an exception occurs it’s correctly closed in a finally {} statement.</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:10pt;font-family:Arial"> </span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:10pt;font-family:Arial">I don't really think it’s a code problem also because:</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:10pt;font-family:Arial"> </span></p> <ul style="margin-top:0in" type=disc> <li class=MsoNormal style="margin:0in 0in 0pt;tab-stops:list .5in"><span style="font-size:10pt;font-family:Arial">We implemented a very big quantity of code in these years and we manage always exceptions.</span></li></ul> <p class=MsoNormal style="margin:0in 0in 0pt 0.5in"><span style="font-size:10pt;font-family:Arial">Everything works fine and when the problem occurs (randomly) all our libraries have this problem. In a particular point of code we can have an error but not everywhere.</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:10pt;font-family:Arial"> </span></p> <ul style="margin-top:0in" type=disc> <li class=MsoNormal style="margin:0in 0in 0pt;tab-stops:list .5in"><span style="font-size:10pt;font-family:Arial">A lot of persons are experiencing this problem, considering also how this thread is old, and I didn’t see a solution introducing exception logic also because an exception logic it’s standard during DB access to close it correctly. </span></li></ul> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:10pt;font-family:Arial"> </span></p> <ul style="margin-top:0in" type=disc> <li class=MsoNormal style="margin:0in 0in 0pt;color:black;tab-stops:list .5in"><span style="font-size:10pt;color:windowtext;font-family:Arial">I’m not able to figure out how .net can </span><span style="font-size:10pt;font-family:Arial">returns a result set of another SQLCommand called by other code, also a different library, executed for a different user request when a connection it’s not properly closed or a timeout event happen.</span></li></ul> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:10pt;color:black;font-family:Arial"> </span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:10pt;color:black;font-family:Arial">You wrote: “But it's hard to explain the crossed data and invalid recordsets otherwise.<span style="">  </span>How does my code run rs.executereader, then iterate the resultset and not find the columns?” I have your same question</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:10pt;font-family:Arial"> </span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:10pt;font-family:Arial">Thanks,</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:10pt;font-family:Arial">Emanuele<span style="">  </span></span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:10pt;font-family:Arial"> </span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:10pt;font-family:Arial">Have you turned on your connection pool?</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:10pt;font-family:Arial"> </span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:10pt;font-family:Arial">Can “Timeout + connection pool on” give this type of problem under certain conditions also if everything is manage correctly (exceptions)?</span></p>Fri, 11 May 2007 18:14:33 Z2007-05-11T18:14:33Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#e71a5b28-6587-40d9-bd39-b00374cb08f4http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#e71a5b28-6587-40d9-bd39-b00374cb08f4Lee Murawski _o2http://social.msdn.microsoft.com/Profile/en-US/?user=Lee%20Murawski%20_o2SQLDataReader.GetOrdinal() fails rarely with IndexOutOfRange<div class=quote> <table width="85%"> <tbody> <tr> <td class=txt4> <strong>Emanuele wrote:</strong></td></tr> <tr> <td class=quoteTable> <table width="100%"> <tbody> <tr> <td class=txt4 valign=top width="100%"> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:10pt;font-family:Arial"></span> </p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:10pt;font-family:Arial">Have you turned on your connection pool?</span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:10pt;font-family:Arial"> </span></p> <p class=MsoNormal style="margin:0in 0in 0pt"><span style="font-size:10pt;font-family:Arial">Can “Timeout + connection pool on” give this type of problem under certain conditions also if everything is manage correctly (exceptions)?</span></p> <p></p></td></tr></tbody></table></td></tr></tbody></table></div> <p></p> <p> </p> <p>I still have connection pooling off and have not had this error happen.</p> <p> </p> <p>There was usually a timeout error prior to this error starting.  I usally had to do a iisreset to correct it.</p>Fri, 11 May 2007 18:39:52 Z2007-05-11T18:39:52Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#bdada6a7-7555-40c3-bdae-984682809c19http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#bdada6a7-7555-40c3-bdae-984682809c19Martin Fentonhttp://social.msdn.microsoft.com/Profile/en-US/?user=Martin%20FentonSQLDataReader.GetOrdinal() fails rarely with IndexOutOfRange<p>Hi all,</p> <p> </p> <p>So I've read over this thread. It seems that I'm not the only person with this issue and it's about time that it got sorted. It would be great if our friends in MS got on board and dealt with this issue - 2 years and counting is quite a long time</p> <p> </p> <p>Our setup:</p> <ul> <li>ASP.Net 2.0 and Sql Server 2005. This is a new issue that presented itself in the last few months. We migrated to ASP.Net 2.0 shortly before. <li>Comprehensive web-based database application with up 500 users login to the system on a daily basis. <li>Basically a four layer application architecture: UI -&gt; Business Objects -&gt; DAL -&gt; Database. <li>Data access layer provides our data access methods such as GetDataReader. It manages the connections to the database, command objects, exception handling etc, and also includes type-safe reader methods. <li>DataException are caught in the DAL and thrown up the application layers, adding appropriate information as required.</li></ul> <p>The problem:</p> <ul> <li>This morning we received many error notifications all of which easily recognisable as a missing column in a data reader. <li>I tried logging into the system and could not - serious problem of down time for our customers. <li>I quickly realised that to get the system back up and running I would have to restart either SQL Server or IIS. I opted for the former and it solved the problem, for now. <li>The issue has occurred once before and that time, if I remember correctly, it resolved itself after a while. We cannot afford to let it &quot;resolve itself&quot;. <li>Example of error message:</li></ul> <p>System.IndexOutOfRangeException: <br>Message:                    </p> <p>OrgID <br>Source:                     </p> <p>System.Data <br>Targetsite:                 </p> <p>Int32 GetOrdinal(System.String) <br>Stacktrace:                 </p> <p>at System.Data.ProviderBase.FieldNameLookup.GetOrdinal(String fieldName) </p> <p>at System.Data.SqlClient.SqlDataReader.GetOrdinal(String name) </p> <p>at System.Data.SqlClient.SqlDataReader.get_Item(String name) </p> <p>at Chip.DAL.Utilities.getIntFromDataReader(SqlDataReader dr, String name) </p> <p>at Chip.BusinessObjects.OrgAddressUser.OrgAddressUser.Read() </p> <p> </p> <p> </p> <p>Comments</p> <ul> <li>We simply cannot turn off connection pooling - it would cause far greater problems given the size of our application. <li>The problem may be related to load but given that today was just a normal day (i.e. no extra load) then I suspect this is not the issue. <li>A number of people who posted suggested restartng IIS. If it happens again I may try that. <li>I modified our code to trace extra exception details as follows:</li></ul> <ol> <li>If reader.HasRows is true [Note: in our case this should always return true given that we already use reader.Read() which return true if records have been returned] <li>Atttempt to read the column <li>Catch the System.IndexOutOfRangeException <li>Trace out the exception. <li>Trace out the properties FieldCount and HasRows of the reader object. <li>Trace the XML representation of the reader [GetSchemaTable()]</li></ol> <ul> <li>If I get the results for this I will post them on this thread. However, given that it has happened only twice in the last few months I don't expect the issue to occur any time soon again. <li>Also note that there were no new deployments lately so the application state has not been modified in any way to cause these issues. <li>There is also the problem in trying to resolve this issue as I cannot replicate it and so cannot be sure that any change I make has resolved it. So any change I make to the system will not be done lightly. <li>Some of the other comments on this thread included:</li></ul> <p>&quot;Microsoft recommends not passing the SqlDataReader to another method and avoiding any static methods usage, they are not sure this is the root cause to this Exception.&quot;. </p> <p> </p> <p>&quot;The problem was that my dataAccess connections and methods were defined as STATIC, which means that sometimes the datareader was receiving data from other tables.&quot;</p> <ul> <li>Surely it makes more sense for the methods to be static? Otherwise the object would have to be instantiated each and every time we want to do a data access. <li>Please explain how the data reader could be receiving data for other tables?</li></ul> <p>I suspect that this is a MS issue. Possibly with ADO.Net, connection pooling or even some sort of memory corruption on either SQL Server or IIS. The fact that restarting SQL Server resolved the issue, as well as restarting IIS raises a number of questions don't you think?</p> <p> </p> <p>Any advice or comments are appreciated.</p> <p> </p> <p>Cheers,</p> <p>Martin</p>Tue, 15 May 2007 15:10:47 Z2007-05-15T15:10:47Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#81e2d8b5-1794-4aa6-9d9c-1ca05435acd3http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#81e2d8b5-1794-4aa6-9d9c-1ca05435acd3andrewkghttp://social.msdn.microsoft.com/Profile/en-US/?user=andrewkgSQLDataReader.GetOrdinal() fails rarely with IndexOutOfRange<p align=left><font face=Arial size=2></font> </p>No posts in over 6 months, has anyone found a resolution to this problem?Mon, 19 Nov 2007 22:03:38 Z2007-11-19T22:03:38Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#3c82bc8b-5ae2-4201-8b36-aa65f86480fchttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#3c82bc8b-5ae2-4201-8b36-aa65f86480fcMartin Fentonhttp://social.msdn.microsoft.com/Profile/en-US/?user=Martin%20FentonSQLDataReader.GetOrdinal() fails rarely with IndexOutOfRange<p align=left><font face=Arial size=2>Hi Andrew,</font></p> <p align=left> </p> <p align=left>We decided to refactor our data access code such that the SqlDataReader object is no longer being passed into the static reader methods. This has been deployed and we have no problems yet. However, I would not be absolutely certain that this resolved this issue. The orginal problem for us only arose very infrequently - every few months or so - and only since we migrated to .NET 2.0 at the start of this year. I suspect that it may have been a memory issue.</p> <p> </p> <p align=left>Regards,</p> <p align=left>Martin</p>Tue, 20 Nov 2007 10:08:27 Z2007-11-20T10:08:27Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#b6bf43bf-1ff0-476e-912c-bf3312ec9966http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#b6bf43bf-1ff0-476e-912c-bf3312ec9966Lee Murawski _o2http://social.msdn.microsoft.com/Profile/en-US/?user=Lee%20Murawski%20_o2SQLDataReader.GetOrdinal() fails rarely with IndexOutOfRange<p align=left><font face=Arial size=2></font> </p>We are still running with connection pooling off without any issues.Tue, 20 Nov 2007 16:45:07 Z2007-11-20T16:45:07Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#9143eb6b-fa7a-4f39-a0cf-566b36255f59http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#9143eb6b-fa7a-4f39-a0cf-566b36255f59andrewkghttp://social.msdn.microsoft.com/Profile/en-US/?user=andrewkgSQLDataReader.GetOrdinal() fails rarely with IndexOutOfRangeThanks for the replys to this old thread.<br><br>Our problem occurs using .NET 2.0, IIS 6, SQL2K. We are seeing this happen about once a week. When it happens it seems to be either caused by or causing a chain reaction where all the users start to loose their session. We can't reproduce this error, we can't seem to pin point it to any specific place in our code or any specific error, we can't even say that this only happens under heavy load. The only thing that is common is it only happens on our prodcution servers and when it happens there are numerous SQLDataReader.GetOrdinal() failing with IndexOutOfRange. Unfortunately, turning off connection pooling isn't really an option with the load that our servers can find themselves under.<br>Tue, 20 Nov 2007 17:33:27 Z2007-11-20T17:33:27Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#8c953732-5f9c-4803-8e23-c3e7c64d6618http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#8c953732-5f9c-4803-8e23-c3e7c64d6618Martin Fentonhttp://social.msdn.microsoft.com/Profile/en-US/?user=Martin%20FentonSQLDataReader.GetOrdinal() fails rarely with IndexOutOfRange<p><span style="font-size:10pt;font-family:Arial">Hi Andrew,</span></p> <p><span style="font-size:10pt;font-family:Arial"> </span></p> <p><span style="font-size:10pt;font-family:Arial">First of all in response to other comments in this thread I can say that in our case turning of connection pooling is also not an option for us for the same reason.</span></p> <p><span style="font-size:10pt;font-family:Arial"> </span></p> <p><span style="font-size:10pt;font-family:Arial">The problems that you are having sound exactly the same as ours except that we do not have the issue as often. The issue was occurring for us every couple of month’s maybe. That means we are overdue a repeat and this has not happened which suggests that we might resolved this issue.</span></p> <p><span style="font-size:10pt;font-family:Arial"> </span></p> <p><span style="font-size:10pt;font-family:Arial">Can I ask how you bring the application back online after these errors occur? If I remember correctly recycling the ASP.NET worker process/application pool stopped these errors from recurring for us.</span></p> <p><span style="font-size:10pt;font-family:Arial"> </span></p> <p><span style="font-size:10pt;font-family:Arial">I also recall that the active worker process visible in the Task Manager had large amounts of memory usage. After recycling the worker process the issue was resolved and new worker process had started. I wonder does this suggest that the issue is memory related corruption possibly related to ADO.NET/Connection Pooling?</span></p> <p><span style="font-size:10pt;font-family:Arial"> </span></p> <p><span style="font-size:10pt;font-family:Arial">I read the following comment:</span></p> <p><span style="font-size:10pt;font-family:Arial"> </span></p> <p><span style="font-size:10pt;font-family:Arial">&quot;Microsoft recommends not passing the SqlDataReader to another method and avoiding any static methods usage, they are not sure this is the root cause to this Exception.&quot;. </span></p> <p><span style="font-size:10pt;font-family:Arial"> </span></p> <p><span style="font-size:10pt;font-family:Arial">We modified out data access helper classes to ensure that SqlDataReader objects are not passed into any static (or otherwise) methods.</span></p> <p><span style="font-size:10pt;font-family:Arial"> </span></p> <p><span style="font-size:10pt;font-family:Arial">We cannot be absolutely certain that this has resolved the issue but it is likely given that we are overdue a re-occurrence of this issue.</span></p> <p><span style="font-size:10pt;font-family:Arial"> </span></p> <p><span style="font-size:10pt;font-family:Arial">Hope this helps,</span></p> <p><span style="font-size:10pt;font-family:Arial"> </span></p> <p><span style="font-size:10pt;font-family:Arial">Martin</span></p> <p><span style="font-size:10pt;font-family:Arial"></span></p>Wed, 21 Nov 2007 09:42:51 Z2007-11-21T09:42:51Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#c13d795b-fcde-4bf0-95f4-0138e2a6876ehttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#c13d795b-fcde-4bf0-95f4-0138e2a6876eandrewkghttp://social.msdn.microsoft.com/Profile/en-US/?user=andrewkgSQLDataReader.GetOrdinal() fails rarely with IndexOutOfRangeHi Martin <p align=left><font face=Arial size=2></font> </p> <p>When the problem occurs, we have to fail over to our backup server. We have tried restarting IIS, but that didn't resolve the problem. I haven't tried specifically recycling the ASP.NET pool (wouldn't restarting IIS accomplish the same thing?)</p> <p align=left> </p> <p align=left>Right now we are in the process of modifying our data access classes so that we are &quot;...avoiding any static method usage.&quot; It will take a while before we are ready to deploy those changes.</p> <p> </p> <p align=left>I'm not sure that the IndexOutOfRange and the massive loss of session are necessarily related. Were you also seeing all of your users suddenly start loosing session? We are also currently in the process of talking directly to MSFT support about this now, hopefully they will be able to get to the bottom of this quicker than we have.</p> <p> </p>Mon, 26 Nov 2007 20:00:29 Z2007-11-26T20:00:29Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#14706a35-0235-4ab2-8b1b-c537c8794b5ahttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#14706a35-0235-4ab2-8b1b-c537c8794b5aMartin Fentonhttp://social.msdn.microsoft.com/Profile/en-US/?user=Martin%20FentonSQLDataReader.GetOrdinal() fails rarely with IndexOutOfRange<p><span style="font-size:10pt;font-family:Arial">Hi Andrew,</span></p> <p><span style="font-size:10pt;font-family:Arial"> </span></p> <p><span style="font-size:10pt;font-family:Arial">This suggests that the problem you are experiencing might be different. Or there may be two issues here: the IndexOutOfRange issue which is the one we are experiencing and the loss of session.</span></p> <p><span style="font-size:10pt;font-family:Arial"> </span></p> <p><span style="font-size:10pt;font-family:Arial">We never had any issue with users’ sessions. And you are correct in saying that restarting IIS would restart the application pool.</span></p> <p><span style="font-size:10pt;font-family:Arial"> </span></p> <p><span style="font-size:10pt;font-family:Arial">Please keep me posted on what the MS support team suggest.</span></p> <p><span style="font-size:10pt;font-family:Arial"> </span></p> <p><span style="font-size:10pt;font-family:Arial">Good luck with it,</span></p> <p><span style="font-size:10pt;font-family:Arial">Martin</span></p> <p class=MsoNormal style="margin:0cm 0cm 0pt"><font face="Times New Roman" size=3> </font></p>Tue, 27 Nov 2007 09:09:30 Z2007-11-27T09:09:30Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#ec51bcef-13bb-4da0-bd06-7e79b5ea9043http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#ec51bcef-13bb-4da0-bd06-7e79b5ea9043while truehttp://social.msdn.microsoft.com/Profile/en-US/?user=while%20trueSQLDataReader.GetOrdinal() fails rarely with IndexOutOfRange<p align=left><font face=Arial size=2>Hello,</font></p> <p align=left> </p> <p align=left>We experienced this problem for the first time today and a quick restart of the website seemed to get things running again (I added a space to the end of the connection string which had two effects - it restarted the website and caused a new connection pool to start). I'm not sure that my manager sees this as a solution to the problem however <img height=19 alt=Smile src="http://forums.microsoft.com/MSDN/emoticons/emotion-1.gif" width=19> Are there any updates or further developments on a proper workaround for this?</p> <p align=left> </p> <p align=left>I see that turning off connection pooling has worked for one person, but if we can avoid this then I would certainly like to...</p> <p align=left> </p> <p align=left>Thanks</p> <p align=left>P</p>Tue, 12 Feb 2008 11:11:57 Z2008-02-12T11:11:57Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#bf685555-496a-4c65-b219-0a3dd70a69a9http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#bf685555-496a-4c65-b219-0a3dd70a69a9troy_xphttp://social.msdn.microsoft.com/Profile/en-US/?user=troy_xpSQLDataReader.GetOrdinal() fails rarely with IndexOutOfRangeHas anyone figured this out yet?<br><br>I'm having the same issues.  Stable code that's been running for over a year and about 2 weeks ago these problems started happening.  I just turned connection pooling off but that in not an acceptable solution long term.<br>Wed, 19 Mar 2008 17:36:17 Z2008-03-19T17:36:17Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#ef206e80-40c3-4ef1-8a32-8044a76fa50ehttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#ef206e80-40c3-4ef1-8a32-8044a76fa50eandrewkghttp://social.msdn.microsoft.com/Profile/en-US/?user=andrewkgSQLDataReader.GetOrdinal() fails rarely with IndexOutOfRangeWe had some static methods that were being used for our database calls. After opening up an issue with Microsoft they insisted that any calls to the database should not be inside of a static method. After removing all static methods that had anything to do with the database, the problem has disappeared. I should note that the error messages we saw were not always related to the static methods. However, we haven't had any reoccurrence in over a month.<br><br>For now the issue remains open with Microsoft and we’re waiting to see if the problem occurs again. Our web application has cycles of high volume and low volume and right now we’re in a low volume time so the fix hasn’t really been abused.<br><br>Wed, 19 Mar 2008 23:16:36 Z2008-03-19T23:16:36Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#f27d262c-5271-433f-8c6b-6aed3f17c20bhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#f27d262c-5271-433f-8c6b-6aed3f17c20bLee Murawski _o2http://social.msdn.microsoft.com/Profile/en-US/?user=Lee%20Murawski%20_o2SQLDataReader.GetOrdinal() fails rarely with IndexOutOfRangeWhat makes something static vs non-static? <p align=left><font face=Arial size=2></font> </p>Thu, 20 Mar 2008 14:17:53 Z2008-03-20T14:17:53Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#89a34060-92b3-49fb-a635-b7e4269884f3http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#89a34060-92b3-49fb-a635-b7e4269884f3andrewkghttp://social.msdn.microsoft.com/Profile/en-US/?user=andrewkgSQLDataReader.GetOrdinal() fails rarely with IndexOutOfRangeUsing the static modifier when declaring a method makes that method static.<br><br>For more information on using static methods and classes check this out:  <br><a title="http://msdn2.microsoft.com/en-us/library/79b3xss3%28VS.80%29.aspx" href="http://msdn2.microsoft.com/en-us/library/79b3xss3(VS.80).aspx">http://msdn2.microsoft.com/en-us/library/79b3xss3(VS.80).aspx</a><br><br>Thu, 20 Mar 2008 16:49:01 Z2008-03-20T16:49:01Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#943b5861-0d9d-4d82-ab03-5e7e2961a77fhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#943b5861-0d9d-4d82-ab03-5e7e2961a77fLee Murawski _o2http://social.msdn.microsoft.com/Profile/en-US/?user=Lee%20Murawski%20_o2SQLDataReader.GetOrdinal() fails rarely with IndexOutOfRange<p align=left><font face=Arial size=2>Thanks.</font></p> <p align=left> </p> <p align=left>What determines static vs non-static in vb.net?</p>Thu, 20 Mar 2008 17:02:46 Z2008-03-20T17:02:46Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#1f31b858-1edb-4cbf-91f0-70b8b4203df1http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#1f31b858-1edb-4cbf-91f0-70b8b4203df1troy_xphttp://social.msdn.microsoft.com/Profile/en-US/?user=troy_xpSQLDataReader.GetOrdinal() fails rarely with IndexOutOfRangeI've refactored all the code and removed all static methods.  I am returning the connection string in a static method but it's just a string.  And I'm still experiencing the issues.  I turned connection pooling off so hopefully that helps until we can figure out what is causing all this.<br>Thu, 20 Mar 2008 17:53:44 Z2008-03-20T17:53:44Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#753fbdfe-d4c1-4ff0-85b9-fdf6f7f3f55ehttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#753fbdfe-d4c1-4ff0-85b9-fdf6f7f3f55eandrewkghttp://social.msdn.microsoft.com/Profile/en-US/?user=andrewkgSQLDataReader.GetOrdinal() fails rarely with IndexOutOfRange<div class=quote> <table width="85%"> <tbody> <tr> <td class=txt4> <strong>Lee Murawski @o2 wrote:</strong></td></tr> <tr> <td class=quoteTable> <table width="100%"> <tbody> <tr> <td class=txt4 valign=top width="100%"> <p align=left><font face=Arial size=2>Thanks.</font></p> <p align=left> </p> <p align=left>What determines static vs non-static in vb.net?</p></td></tr></tbody></table></td></tr></tbody></table></div><br><br>Found this link for you, maybe it will help <br><a title="http://msdn2.microsoft.com/en-us/library/z2cty7t8.aspx" href="http://msdn2.microsoft.com/en-us/library/z2cty7t8.aspx">http://msdn2.microsoft.com/en-us/library/z2cty7t8.aspx</a> <br><br>Thu, 20 Mar 2008 19:25:28 Z2008-03-20T19:25:28Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#dd5c3cc3-2e34-4dfb-8945-0141b8b36566http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#dd5c3cc3-2e34-4dfb-8945-0141b8b36566ItaiLhttp://social.msdn.microsoft.com/Profile/en-US/?user=ItaiLSQLDataReader.GetOrdinal() fails rarely with IndexOutOfRange<font face=Arial size=2> <p align=left>Hi all,<br>I've encountered the exact same problem, I read the thread <font class="" face=fmisspellt>thoroughly</font> and I think I understand where the error comes from and how you can solve it (With connection pooling on)<br>Lets say I have two <font class=misspellet face=fmisspellt>sql</font> connections, one for fetching data and one for <font class="" face=fmisspellt>retrieving</font> data (<font class=misspellet face=fmisspellt>SqlConnection</font> <font class=misspellet face=fmisspellt>fetchConn</font>, <font class=misspellet face=fmisspellt>insertConn</font>)<br>Now lets say I use the <font class=misspellet face=fmisspellt>insertConn</font> on different thread than <font class=misspellet face=fmisspellt>fetchConn</font>, <strong>what can happen (sometimes) is that the following two lines, on two different threads, will give back the same <font class="" face=fmisspellt>actual</font> connection!<br></strong> <div class=codeseg> <div class=codecontent> <div class=codesniptitle><span style="width:100%">Code Snippet</span></div> <p align=left>void <font class=misspellet face=fmisspellt>Thread1</font>()<br>{<br> <font class=misspellet face=fmisspellt><font class=misspellet face=fmisspellt>fetchConn</font>.Open</font>();<br>}</p> <p align=left> </p> <p align=left>void <font class=misspellet face=fmisspellt>Thread2</font>()<br>{<br> <font class=misspellet face=fmisspellt><font class=misspellet face=fmisspellt>insertConn</font>.Open</font>();<br>}</p> <p align=left> </p></div></div> <p align=left> </p> <p>Because the Open() method goes to the connection pool and the connection string is the same for the two connections (hence the same connection pool), <strong>it can return the same connection</strong> (<font class=misspellet face=fmisspellt>SqlConnection</font> methods are not thread safe)<br><strong>and even though we have two different <font class=misspellet face=fmisspellt>SqlConnection</font> objects</strong>, the pooling <font class="" face=fmisspellt>mechanism</font> makes it the same scenario as using the same connection object from two different thread.<br>From now on the <font class=misspellet face=fmisspellt>behaviour</font> is unexpected and the errors we got seems more reasonable now..<br>This also explains why turning off the connection pooling solves the problem.<br>If you do want to use connection pooling, you'll have to understand this issue and fix the thread <font class="" face=fmisspellt>safety</font> issues resolved from it. <br><strong>The solution</strong> will be specific for each case but a very easy patch you can apply to check if it solves your problem is to change something in the connection string of every connection you use at a different thread, so it will have a different pool.<br>If you're not using (knowingly) any other threads, you have to check that a thread is not started for you by any lower level <font class="" face=fmisspellt>infrastructure</font> which makes your code run at different thread.. (some callbacks might be on different thread for instance)<br>I hope this helps you, if you think it's <font class="" face=fmisspellt>entirety</font> not the case for you, I'm sorry for wasting your time<img alt=Wink src="http://forums.microsoft.com/MSDN/emoticons/emotion-5.gif"></p> <p><font class=misspellet face=fmisspellt></font> </p> <p align=left><font class=misspellet face=fmisspellt>Itai</font>.</p></font>Sun, 20 Apr 2008 17:51:43 Z2008-04-20T17:51:43Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#dd16331d-5c6e-4cb0-bc84-dbe313ee635chttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#dd16331d-5c6e-4cb0-bc84-dbe313ee635cAndydddhttp://social.msdn.microsoft.com/Profile/en-US/?user=AndydddSQLDataReader.GetOrdinal() fails rarely with IndexOutOfRange<p>I found there is a kb article talk about <font color="#000000">IndexOutOfRangeException, </font></p> <p align=left><a title="http://support.microsoft.com/kb/948176/en-us" href="http://support.microsoft.com/kb/948176/en-us">http://support.microsoft.com/kb/948176/en-us</a></p> <p align=left>But ther is not a download for it.</p> <p align=left>Anyone have tried it?</p> <p align=left> </p> <p align=left><font face=Arial size=2></font> </p>Fri, 04 Jul 2008 01:34:33 Z2008-07-04T01:34:33Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#a206757a-c9db-44d8-8f52-aa2e959eb490http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#a206757a-c9db-44d8-8f52-aa2e959eb490RubenPhttp://social.msdn.microsoft.com/Profile/en-US/?user=RubenPSQLDataReader.GetOrdinal() fails rarely with IndexOutOfRange<font size=2><span style="font-family:Arial">Could somebody confirm that the hotfix works? The description doesn't really match the error everybody is facing here.<br><br>And please MS, could someone please pretty please join in. This topic has been lingering without a solution for far too long!<br><br>In the mean time I'll be trying the following code:<br><br></span></font> <div style="text-align:left"><font size=2><span style="font-family:Arial"> <div class=codeseg> <div class=codecontent> <div class=codesniptitle><span style="width:100%">Code Snippet</span></div> <p>lock (String.Intern(conn.ConnectionString))</p> <p>{</p> <p>conn.Open();<br></p> <p>}</p></div></div></span></font><br><font size=2><span style="font-family:Arial"></span></font>I'll try to post the results after several days of testing if this actually helps.<br><font size=2><span style="font-family:Arial"></span></font></div>Thu, 10 Jul 2008 13:52:53 Z2008-07-10T13:52:53Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#bc3c8141-6be5-4a74-8e74-a4f41759b816http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#bc3c8141-6be5-4a74-8e74-a4f41759b816RubenPhttp://social.msdn.microsoft.com/Profile/en-US/?user=RubenPSQLDataReader.GetOrdinal() fails rarely with IndexOutOfRange<font size=2><span style="font-family:Arial">The attempted fix I posted earlier does indeed seem to work, not a single IndexOutOfRangeException anymore. I haven't tried the hotfix yet, but it does seem likely that this hotfix will solve the problem.<br></span></font>Tue, 29 Jul 2008 15:02:55 Z2008-07-29T15:02:55Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#36e0ff71-988c-447f-a552-bcdae4f2b2d8http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#36e0ff71-988c-447f-a552-bcdae4f2b2d8Marzban Doctorhttp://social.msdn.microsoft.com/Profile/en-US/?user=Marzban%20DoctorSQLDataReader.GetOrdinal() fails rarely with IndexOutOfRangeThis hotfix has been supposedly rolled into .NET 3.5, but we are still seeing the same issue occurring on a fairly consistent basis on our web servers with .NET3.5. As our servers are always under fairly heavy load all day, this error keeps popping up at the rate of 800 to 1000 occurrences per day per server. Btw, we use nHibernate 2.0.1 to access SQLServer2K5 database. <br><p><br></p>Can anybody shed new light on this IndexOutOfRangeException issue? Fri, 30 Jan 2009 19:03:14 Z2009-01-30T19:03:14Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#2921ee10-d72c-43cc-959f-e532ca3342b8http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#2921ee10-d72c-43cc-959f-e532ca3342b8Anto Binish Kasparhttp://social.msdn.microsoft.com/Profile/en-US/?user=Anto%20Binish%20KasparSQLDataReader.GetOrdinal() fails rarely with IndexOutOfRange<p>We also having same issue in our production server. </p> <p>Server OS: <strong>Windows Server 2008</strong><br>Framework : <strong>3.5</strong></p> <p>We are getting this error on peek hours, and if we refresh the page after some minutes its started working fine.</p> <p>We are using more SQL queries and stored procedure and i noticed that this error occures only for queries which used alias with tables ( i am may be wrong ).</p> <p>Anyone found the solution for it.  </p>- Anto Binish Kaspar<br><br>Thu, 19 Feb 2009 15:48:53 Z2009-02-19T15:48:53Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#aac4eebc-9790-44e2-a657-9205c97ab926http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#aac4eebc-9790-44e2-a657-9205c97ab926HaniBeyhttp://social.msdn.microsoft.com/Profile/en-US/?user=HaniBeySQLDataReader.GetOrdinal() fails rarely with IndexOutOfRangeA client of ours just reported encountering this error.<br><br>Our application is a windows application not a web application.<br>We're using .NET 2.0 and SQL Server 2005.<br><br>The application has been running fine for over 4 months and this is the first time we see this error.<br><br><div style="overflow:auto;background-color:white;line-height:100% ! important;font-family:Courier New;font-size:11px"><table style="border-width:0px;margin:2px 0px;width:99%;border-collapse:collapse;background-color:rgb(255, 255, 255)" cellpadding=0 cellspacing=0><col style="font-family:Courier New;font-size:11px;padding-left:10px;white-space:nowrap"><tbody><tr><td><font style="font-size:11px">    Private Function getID() As Long </font></td></tr><tr><td style="background-color:rgb(247, 247, 247)">        Dim strSQL As String </td></tr><tr><td>        Dim drsql As SqlClient.SqlDataReader </td></tr><tr><td style="background-color:rgb(247, 247, 247)">        <font style="color:red">strSQL</font><font style="font-size:11px"> = </font><font style="color:blue">&quot;SELECT line_Id from lines where line_Number='&quot;</font><font style="font-size:11px"> &amp; line_Name &amp; &quot;' and </font><font style="color:red">site_id</font><font style="font-size:11px">=&quot; &amp; siteid </font></td></tr><tr><td>        <font style="color:red">drsql</font><font style="font-size:11px"> = </font><font style="color:blue">selectCMD</font><font style="font-size:11px">(strSQL) </font></td></tr><tr><td style="background-color:rgb(247, 247, 247)">        If <font style="color:red">drsql.HasRows</font><font style="font-size:11px"> = </font><font style="color:blue">True</font><font style="font-size:11px"> Then </font></td></tr><tr><td>            drsql.Read() </td></tr><tr><td style="background-color:rgb(247, 247, 247)">            <font style="color:red">getID</font><font style="font-size:11px"> = </font><font style="color:blue">drsql</font><font style="font-size:11px">(&quot;line_Id&quot;) </font></td></tr><tr><td>        Else </td></tr><tr><td style="background-color:rgb(247, 247, 247)">            <font style="color:red">getID</font><font style="font-size:11px"> = -1 </font></td></tr><tr><td>        End If </td></tr><tr><td style="background-color:rgb(247, 247, 247)">        drsql.Close() </td></tr><tr><td>    End Function </td></tr><tr><td style="background-color:rgb(247, 247, 247)"> </td></tr><tr><td>    Public Function selectCMD(ByVal strSQL As String) As SqlDataReader </td></tr><tr><td style="background-color:rgb(247, 247, 247)">        Try </td></tr><tr><td>            If <font style="color:red">cnSQL.State</font><font style="font-size:11px"> = </font><font style="color:blue">ConnectionState</font><font style="font-size:11px">.Open Then </font></td></tr><tr><td style="background-color:rgb(247, 247, 247)">                Dim cmdSQL As New SqlCommand(strSQL, cnSQL) </td></tr><tr><td>                <font style="color:red">cmdSQL.CommandTimeout</font><font style="font-size:11px"> = </font><font style="color:blue">180</font><font style="font-size:11px"> </font></td></tr><tr><td style="background-color:rgb(247, 247, 247)">                <font style="color:red">selectCMD</font><font style="font-size:11px"> = </font><font style="color:blue">cmdSQL</font><font style="font-size:11px">.ExecuteReader </font></td></tr><tr><td>                'log(strSQL, EventLogEntryType, 123) </td></tr><tr><td style="background-color:rgb(247, 247, 247)">            Else </td></tr><tr><td>                If openConnection() = True Then </td></tr><tr><td style="background-color:rgb(247, 247, 247)">                    <font style="color:red">selectCMD</font><font style="font-size:11px"></font><font style="color:blue">selectCMD</font><font style="font-size:11px"> = selectCMD(strSQL) </font></td></tr><tr><td>                Else </td></tr><tr><td style="background-color:rgb(247, 247, 247)">                    Return Nothing </td></tr><tr><td>                End If </td></tr><tr><td style="background-color:rgb(247, 247, 247)">            End If </td></tr><tr><td>        Catch ex As Exception </td></tr><tr><td style="background-color:rgb(247, 247, 247)">            Dim exString As String </td></tr><tr><td>            <font style="color:red">exString</font><font style="font-size:11px"> = </font><font style="color:blue">&quot;Error in SELECT statement &quot;</font><font style="font-size:11px"> &amp; vbCrLf &amp; strSQL &amp; vbCrLf &amp; ex.ToString &amp; &quot;.&quot; </font></td></tr><tr><td style="background-color:rgb(247, 247, 247)">            log(exString, EventLogEntryType.Error, 108) </td></tr><tr><td>            <font style="color:red">selectCMD</font><font style="font-size:11px"> = </font><font style="color:blue">Nothing</font><font style="font-size:11px"> </font></td></tr><tr><td style="background-color:rgb(247, 247, 247)">        End Try </td></tr><tr><td>    End Function </td></tr></tbody></table></div><br> Fri, 20 Feb 2009 10:52:33 Z2009-02-20T10:52:33Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#dfbb7771-348f-49d1-b087-7b90c4bac141http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#dfbb7771-348f-49d1-b087-7b90c4bac141oliver0303http://social.msdn.microsoft.com/Profile/en-US/?user=oliver0303SQLDataReader.GetOrdinal() fails rarely with IndexOutOfRange We are also experincing these errors.<br><br>Any update to this other then disabling pooling ? We have now implemented this and will see if the errors disappears. We now that disabling pooling is very bad for performance, but we a re beginning to get desperate, as we have dealt with this for the last 5 weeks, encountering this error 2-3 times a week.<br><br>We are using Windows 2008, Sql Server 2008 and .net 3.5Mon, 02 Mar 2009 12:46:31 Z2009-03-02T12:47:00Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#a982f1a2-30ea-4efc-bd75-80700d6602ffhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#a982f1a2-30ea-4efc-bd75-80700d6602ffAnto Binish Kasparhttp://social.msdn.microsoft.com/Profile/en-US/?user=Anto%20Binish%20KasparSQLDataReader.GetOrdinal() fails rarely with IndexOutOfRange <strong>Problem is fixed for me <br><br></strong>I did three steps and updated the application to live server before 15 days, still we dint get any errors in live website. We used to get aleast once in a day but now its fixed. Here is my three steps<br><br> <ol> <li>It was using try, catch and finally to close the connection. i changed to &quot;USING&quot;</li> <li>I was using static function to create a new connection for eg SqlConnection connection = Util.GetConnection(); i changed it to public function, like this SqlConnection connection = new Util.GetConnection();</li> <li>I called Dispose() function of SqlReader after Close() function call. </li></ol><br><strong>Before</strong><br><br><font size=2> <p></p></font> <p><font color="#a65300" size=2><font color="#a65300" size=2>SqlConnection</font></font> <font color="#800000" size=2><font color="#800000" size=2>connection</font></font><font size=2> = </font><font color="#a65300" size=2><font color="#a65300" size=2>Util</font></font><font size=2>.</font><font color="#800000" size=2><font color="#800000" size=2>GetConnection</font></font><font size=2>();<br></font><font color="#a65300" size=2><font color="#a65300" size=2>SqlDataReader</font></font> <font color="#800000" size=2><font color="#800000" size=2>reader</font></font><font size=2> = </font><font color="#000080" size=2><font color="#000080" size=2>null</font></font><font size=2>;<br></font><font color="#a65300" size=2><font color="#a65300" size=2>SqlCommand</font></font> <font color="#800000" size=2><font color="#800000" size=2>command</font></font><font size=2> = </font><font color="#000080" size=2><font color="#000080" size=2>null</font></font><font size=2>; <p></p> <p></p></font> <p></p> <p><font color="#000080" size=2><font color="#000080" size=2>try<br></font></font><font size=2>{<br></font><font color="#800000" size=2><font color="#800000" size=2>    command</font></font><font size=2> = </font><font color="#000080" size=2><font color="#000080" size=2>new</font></font> <font color="#a65300" size=2><font color="#a65300" size=2>SqlCommand</font></font><font size=2>(&quot;select a,b,c from blabla&quot;);<br></font><font color="#800000" size=2><font color="#800000" size=2>    reader</font></font><font size=2> = </font><font color="#800000" size=2><font color="#800000" size=2>command</font></font><font size=2>.</font><font color="#800000" size=2><font color="#800000" size=2>ExecuteReader</font></font><font size=2>();<br></font><font color="#000080" size=2><font color="#000080" size=2>    while</font></font><font size=2> (</font><font color="#800000" size=2><font color="#800000" size=2>reader</font></font><font size=2>.</font><font color="#800000" size=2><font color="#800000" size=2>HasRows</font></font><font size=2>)<br>    {<br></font><font color="#008000" size=2><font color="#008000" size=2>        //coder here <br></font></font><font size=2>    }<br>}<br></font><font color="#000080" size=2><font color="#000080" size=2>finally<br></font></font><font size=2>{<br></font><font color="#000080" size=2><font color="#000080" size=2>    if</font></font><font size=2> (</font><font color="#800000" size=2><font color="#800000" size=2>command</font></font><font size=2> != </font><font color="#000080" size=2><font color="#000080" size=2>null</font></font><font size=2>)<br>    {<br></font><font color="#800000" size=2><font color="#800000" size=2>        command</font></font><font size=2>.</font><font color="#800000" size=2><font color="#800000" size=2>Dispose</font></font><font size=2>();<br></font><font color="#800000" size=2><font color="#800000" size=2>        command</font></font><font size=2> = </font><font color="#000080" size=2><font color="#000080" size=2>null</font></font><font size=2>;<br>    }<br></font><font color="#000080" size=2><font color="#000080" size=2>    if</font></font><font size=2> (</font><font color="#800000" size=2><font color="#800000" size=2>reader</font></font><font size=2> != </font><font color="#000080" size=2><font color="#000080" size=2>null</font></font><font size=2>)<br>    {<br></font><font color="#800000" size=2><font color="#800000" size=2>        reader</font></font><font size=2>.</font><font color="#800000" size=2><font color="#800000" size=2>Close</font></font><font size=2>();<br>    }<br></font><font color="#800000" size=2><font color="#800000" size=2>    connection</font></font><font size=2>.</font><font color="#800000" size=2><font color="#800000" size=2>Close</font></font><font size=2>();<br></font><font color="#800000" size=2><font color="#800000" size=2>    connection</font></font><font size=2>.</font><font color="#800000" size=2><font color="#800000" size=2>Dispose</font></font><font size=2>();<br>} <p></p></font> <p></p><br><br><strong>After<br><br></strong><font size=2> <p></p></font> <p><font color="#000080" size=2><font color="#000080" size=2>using</font></font><font size=2> (</font><font color="#a65300" size=2><font color="#a65300" size=2>SqlConnection</font></font> <font color="#800000" size=2><font color="#800000" size=2>connection</font></font><font size=2> = </font><font color="#a65300" size=2><font color="#a65300" size=2>Util</font></font><font size=2>.</font><font color="#800000" size=2><font color="#800000" size=2>GetConnection</font></font><font size=2>())<br>{<br></font><font color="#000080" size=2><font color="#000080" size=2>    using</font></font><font size=2> (</font><font color="#a65300" size=2><font color="#a65300" size=2>SqlCommand</font></font> <font color="#800000" size=2><font color="#800000" size=2>command</font></font><font size=2> = </font><font color="#000080" size=2><font color="#000080" size=2>new</font></font> <font color="#a65300" size=2><font color="#a65300" size=2>SqlCommand</font></font><font size=2>(&quot;select a,b,c from blabla&quot;))<br>    {</font><font color="#000080" size=2><font color="#000080" size=2><br>        using</font></font><font size=2> (</font><font color="#a65300" size=2><font color="#a65300" size=2>SqlDataReader</font></font> <font color="#800000" size=2><font color="#800000" size=2>reader</font></font><font size=2> = </font><font color="#800000" size=2><font color="#800000" size=2>command</font></font><font size=2>.</font><font color="#800000" size=2><font color="#800000" size=2>ExecuteReader</font></font><font size=2>())<br>        {<br></font><font color="#000080" size=2><font color="#000080" size=2>            while</font></font><font size=2> (</font><font color="#800000" size=2><font color="#800000" size=2>reader</font></font><font size=2>.</font><font color="#800000" size=2><font color="#800000" size=2>HasRows</font></font><font size=2>)<br>            {<br></font><font color="#008000" size=2><font color="#008000" size=2>                //coder here <br></font></font><font size=2>            }<br></font><font color="#800000" size=2><font color="#800000" size=2>            reader</font></font><font size=2>.</font><font color="#800000" size=2><font color="#800000" size=2>Close</font></font><font size=2>();<br></font><font color="#800000" size=2><font color="#800000" size=2>            reader</font></font><font size=2>.</font><font color="#800000" size=2><font color="#800000" size=2>Dispose</font></font><font size=2>();<br>        }<br></font><font color="#800000" size=2><font color="#800000" size=2>        command</font></font><font size=2>.</font><font color="#800000" size=2><font color="#800000" size=2>Dispose</font></font><font size=2>();<br>    }<br></font><font color="#800000" size=2><font color="#800000" size=2>    connection</font></font><font size=2>.</font><font color="#800000" size=2><font color="#800000" size=2>Close</font></font><font size=2>();<br></font><font color="#800000" size=2><font color="#800000" size=2>    connection</font></font><font size=2>.</font><font color="#800000" size=2><font color="#800000" size=2>Dispose</font></font><font size=2>();<br>} <p></p></font> <p></p>Above code is not actual one, its just the format.<br><br><br>Only these changes i did in my project. And errors gone. Please try this solution. <br><br><br>Thanks,<br>Anto Binish Kaspar Sat, 07 Mar 2009 21:19:38 Z2009-03-07T21:19:38Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#ede72468-b2e1-422f-bc68-f6736597cdd1http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#ede72468-b2e1-422f-bc68-f6736597cdd1Ishitorihttp://social.msdn.microsoft.com/Profile/en-US/?user=IshitoriSQLDataReader.GetOrdinal() fails rarely with IndexOutOfRange Hello everyone,<br><br>I have read the topic thoroughly since I experience the same problem as described above. The situation is similar: I do an query to a stored procedure and sometimes get IndexOutOfRange exception. It occurs rarely and only during peak hours. I was unable to reproduce the problem on my developer's environment.<br><br>I found the reason why it fails sometimes. The problem is that returned resultset is invalid and has no relation to initial query. Consider this example:<br><br>There is a database with 2 tables: one stores information about websites with a default domain name and another table contains additional domain names to each website. I have a stored procedure which fetch website Id by domain name. I call the procedure using pure ado.net without any additional frameworks. Here is the code:<br><br> <div style="border-right:#7f9db9 1px solid;border-top:#7f9db9 1px solid;font-size:11px;overflow:auto;border-left:#7f9db9 1px solid;line-height:100%! important;border-bottom:#7f9db9 1px solid;font-family:Courier New;background-color:white"> <table style="border-top-width:0px;border-left-width:0px;margin:2px 0px;width:99%;border-bottom:#eee 0px solid;border-collapse:collapse;background-color:#fff;border-right-width:0px" cellspacing=0 cellpadding=0> <colgroup> <col style="padding-left:10px;font-size:11px;border-bottom:#f7f7f7 1px solid;font-family:Courier New;white-space:nowrap"> <tbody> <tr> <td><font style="font-size:11px">            IDbCommand </font><font style="color:red">command</font><font style="font-size:11px"> = </font><font style="color:blue">new</font><font style="font-size:11px"> SqlCommand();  </font></td></tr> <tr> <td style="background-color:#f7f7f7">            </font><font style="color:red">command.Connection</font><font style="font-size:11px"> = </font><font style="color:blue">new</font><font style="font-size:11px"> SqlConnection(connectionString);  </font></td></tr> <tr> <td>            </font><font style="color:red">command.CommandType</font><font style="font-size:11px"> = CommandType.StoredProcedure;  </font></td></tr> <tr> <td style="background-color:#f7f7f7">            </font><font style="color:red">command.CommandText</font><font style="font-size:11px"> = </font><font style="color:blue">&quot;[dbo].[GetWebSiteId]&quot;</font><font style="font-size:11px">;  </font></td></tr> <tr> <td>            dataService.AddDbCommandParameter(command, &quot;hostname&quot;, urlName);  </td></tr> <tr> <td style="background-color:#f7f7f7">            dataService.AddDbCommandParameter(command, &quot;hostname2&quot;, urlName2);  </td></tr> <tr> <td> </td></tr> <tr> <td style="background-color:#f7f7f7">            object <font style="color:red">dirtyWebsiteId</font><font style="font-size:11px"> = </font><font style="color:blue">0</font><font style="font-size:11px">;  </font></td></tr> <tr> <td>            IDataReader </font><font style="color:red">reader</font><font style="font-size:11px"> = </font><font style="color:blue">null</font><font style="font-size:11px">;  </font></td></tr> <tr> <td style="background-color:#f7f7f7"> </td></tr> <tr> <td>            try  </td></tr> <tr> <td style="background-color:#f7f7f7">            {  </td></tr> <tr> <td>                command.Connection.Open();  </td></tr> <tr> <td style="background-color:#f7f7f7">                </font><font style="color:red">reader</font><font style="font-size:11px"> = </font><font style="color:blue">command</font><font style="font-size:11px">.ExecuteReader();  </font></td></tr> <tr> <td> </td></tr> <tr> <td style="background-color:#f7f7f7">                if (reader.Read())  </td></tr> <tr> <td>                {  </td></tr> <tr> <td style="background-color:#f7f7f7">                    <font color="#ff0000">dirtyWebsiteId</font><font style="font-size:11px"> </font><font style="font-size:11px">= </font><font style="color:blue">reader</font><font style="font-size:11px">[0];  </font></td></tr> <tr> <td>                }  </td></tr> <tr> <td style="background-color:#f7f7f7">            }  </td></tr> <tr> <td>            finally  </td></tr> <tr> <td style="background-color:#f7f7f7">            {  </td></tr> <tr> <td>                if (reader != null &amp;&amp; !reader.IsClosed)  </td></tr> <tr> <td style="background-color:#f7f7f7">                {  </td></tr> <tr> <td>                    reader.Close();  </td></tr> <tr> <td style="background-color:#f7f7f7">                }  </td></tr> <tr> <td> </td></tr> <tr> <td style="background-color:#f7f7f7">                command.Connection.Close();  </td></tr> <tr> <td>            } <br><br>            if (!(<font color="#ff0000">dirtyWebsiteId</font><font style="font-size:11px"> is int</font>)) <br>            {<br>                throw new Exception(&quot;It must be int!&quot;);<br>            }</td></tr> <tr> <td style="background-color:#f7f7f7"> </td></tr></tbody></table></div>And here is the code of the stored procedure where hostname2 is &quot;www.&quot; + hostname:<br><br> <div style="border-right:#7f9db9 1px solid;border-top:#7f9db9 1px solid;font-size:11px;overflow:auto;border-left:#7f9db9 1px solid;line-height:100%! important;border-bottom:#7f9db9 1px solid;font-family:Courier New;background-color:white"> <table style="border-top-width:0px;border-left-width:0px;margin:2px 0px;width:99%;border-bottom:#eee 0px solid;border-collapse:collapse;background-color:#fff;border-right-width:0px" cellspacing=0 cellpadding=0> <colgroup> <col style="padding-left:10px;font-size:11px;border-bottom:#f7f7f7 1px solid;font-family:Courier New;white-space:nowrap"> <tbody> <tr> <td><font style="font-size:11px">    </font><font style="color:blue">SET</font><font style="font-size:11px"> NOCOUNT </font><font style="color:blue">ON</font><font style="font-size:11px"> </font></td></tr> <tr> <td style="background-color:#f7f7f7">    </font><font style="color:blue">DECLARE</font><font style="font-size:11px"> @id </font><font style="color:blue">INT</font><font style="font-size:11px"> </font></td></tr> <tr> <td>      </td></tr> <tr> <td style="background-color:#f7f7f7">    </font><font style="color:blue">SELECT</font><font style="font-size:11px"> </font><font style="color:blue">TOP</font><font style="font-size:11px"> 1 @id = </font><font style="color:#ff1493">ISNULL</font><font style="font-size:11px">(w.Id, 0)  </font></td></tr> <tr> <td>        </font><font style="color:blue">FROM</font><font style="font-size:11px"> WebSite w   </font></td></tr> <tr> <td style="background-color:#f7f7f7">        </font><font style="color:#ff1493">LEFT</font><font style="font-size:11px"> </font><font style="color:#808080">JOIN</font><font style="font-size:11px"> WebSiteDomainName wdn </font><font style="color:blue">ON</font><font style="font-size:11px"> w.Id = wdn.WebSiteId   </font></td></tr> <tr> <td>        </font><font style="color:blue">WHERE</font><font style="font-size:11px"> w.UrlName = @hostname   </font></td></tr> <tr> <td style="background-color:#f7f7f7">            </font><font style="color:#808080">OR</font><font style="font-size:11px"> w.UrlName = @hostname2   </font></td></tr> <tr> <td>            </font><font style="color:#808080">OR</font><font style="font-size:11px"> wdn.Url = @hostname   </font></td></tr> <tr> <td style="background-color:#f7f7f7">            </font><font style="color:#808080">OR</font><font style="font-size:11px"> wdn.Url = @hostname2      </font></td></tr> <tr> <td>              </td></tr> <tr> <td style="background-color:#f7f7f7">    IF (@id </font><font style="color:blue">IS</font><font style="font-size:11px"> </font><font style="color:#808080">NULL</font><font style="font-size:11px">)  </font></td></tr> <tr> <td>    </font><font style="color:blue">BEGIN</font><font style="font-size:11px"> </font></td></tr> <tr> <td style="background-color:#f7f7f7">        </font><font style="color:blue">SET</font><font style="font-size:11px"> @id = 0  </font></td></tr> <tr> <td>    </font><font style="color:blue">END</font><font style="font-size:11px"> </font></td></tr> <tr> <td style="background-color:#f7f7f7">      </td></tr> <tr> <td>    </font><font style="color:blue">SELECT</font><font style="font-size:11px"> @id  </font></td></tr> <tr> <td style="background-color:#f7f7f7">    </font><font style="color:blue">SET</font><font style="font-size:11px"> NOCOUNT </font><font style="color:blue">OFF</font><font style="font-size:11px">      </font></td></tr> <tr> <td> </td></tr></tbody></table></div><br>The problem is that it fails and throws the exception. The result is not an Int. As additional logging showed, the result might actually contains a list of objects which is not relevant to the query!<br><br>But what is worse that sometimes it contains Int, but it is not an Id of the website I queried. It is just an Id of a different website. But it is still an Int and cast works perfectly, but <strong>I recieve wrong data</strong>!<br><br>My thought is that somewhere in internals resultsets just became mixed together. One query receives resultset of another query. It happens only at peak time, but not only in this case. I found at least 2 other place where such exception occur. <br><br>I believe turning off of a pooling connection will eliminate the problem, but I can't do this on the live enviroment. And checking HasRows on DataReader wouldn't help too since reader actually has data.<br><br>I've read here that the problem is still exists in .NET 3.5. It is surprising that such a <strong>critical problem</strong> exists in the core of he ADO.NET all this time. Is there any comments of the developers of ADO.NET about the problem?<br><br>P.S. I use .NET 2.0 + MS SQL 2005Mon, 16 Mar 2009 16:23:15 Z2009-03-16T16:23:15Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#b6cbddba-3cbd-461c-a35f-3ebaca982eechttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#b6cbddba-3cbd-461c-a35f-3ebaca982eecMatt Neerincx [MSFT]http://social.msdn.microsoft.com/Profile/en-US/?user=Matt%20Neerincx%20%5bMSFT%5dSQLDataReader.GetOrdinal() fails rarely with IndexOutOfRange<p>Ishitori, could you apply <a href="http://support.microsoft.com/kb/944100">http://support.microsoft.com/kb/944100</a> and see if it resolves your problem?<br>This fix looks closely related to your problem.<br><br>In addition, this is fixed in .NET 2.0 SP2 and later drops of .NET.</p>Tue, 17 Mar 2009 21:28:10 Z2009-03-17T21:28:10Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#3c2aecc7-3d1c-4059-bc6a-2557660590fehttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#3c2aecc7-3d1c-4059-bc6a-2557660590feIshitorihttp://social.msdn.microsoft.com/Profile/en-US/?user=IshitoriSQLDataReader.GetOrdinal() fails rarely with IndexOutOfRange Thanks for the answer, Matt. I've read the article and seems it's telling about losing the data, but not about mixing it in different SqlCommands as it happens in my case. Moreover, I've just checked my live environment settings and found out that SP 2 for .NET 2.0 was already applied. So, I believe it is not the reason.<br><br>For now I have scheduled pool recycling on the web server, but it is a temporary solution and will affect our customers badly. Any other ideas?Wed, 18 Mar 2009 07:33:21 Z2009-03-18T07:33:21Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#6bd1c932-a109-44f8-a114-042897410eefhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#6bd1c932-a109-44f8-a114-042897410eefMatt Neerincx [MSFT]http://social.msdn.microsoft.com/Profile/en-US/?user=Matt%20Neerincx%20%5bMSFT%5dSQLDataReader.GetOrdinal() fails rarely with IndexOutOfRangeOur pooling code is very complex, it has to pool and also be aware of System.Transaction state of threads, manage this with connections to SQL Server, perform transaction escalation when needed, etc...  Also, inside the ASP.NET environment it is very difficult to pool things because ASP.NET uses thread aborts to cancel operations.  You can have a thread in the middle of fetching a resultset from a connection and ASP.NET decides to abort the thread mid-operation.  We added code in .NET 2.0 SP2 (hotfix I described) to attempt to get things back into a clean state when this happens.<br><br>Along with this you can have code that is not thread safe using connections after they are disposed for example, this can cause side effects like phantom results.<br><br>In general we have not seen a clear cut series of customers reporting phantom results.  When we debug the few of these we've seen in the end it usually turns out to be an application issue like multiple threads using same connection, store procs with conditional logic, etc...<br><br>But in any case, I would like to help you get to the bottom of this, whether it's in our code or your code.<br><br>First thing you can do for me is partition the pool instead of turning it off.  For example, you can partition your connection strings in different parts of your application to isolate the source of the problem.  This help us isolate the repro code more precisely.<br><br>To partition, append a unique keyword to end of your connectiuon strings, for example:<br><br>using (SqlConnection conn = new SqlConnection(connectionString + &quot;;Application Name=FunctionName;&quot;))<br>{<br>...<br>}<br><br>You don't need to necessarily use a FunctionName level of isolate, you can use for example FileName for example to scope the issue to file scope.<br><br>Do this to see which particular files are having the problems, this will help isolate the code to reproduce the problem.   You can then further partition down to function level to isolate which functions are having the impact.<br><br>Like the previous poster's mentioned, be sure to clearly deal with SqlConnection, SqlDataReader objects and call Close on them in method scope when possible.  Avoid SqlConnection objects that exceed method scope.  Avoid storing SqlConnection objects as class members, etc...  The general rule is open as late as possible and close as soon as possible, this is most beneficial to pooling performance.<br><br><br><br>Wed, 18 Mar 2009 17:33:09 Z2009-03-18T17:33:09Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#e7522264-e15a-4291-a67b-a90deb2d3631http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#e7522264-e15a-4291-a67b-a90deb2d3631Ishitorihttp://social.msdn.microsoft.com/Profile/en-US/?user=IshitoriSQLDataReader.GetOrdinal() fails rarely with IndexOutOfRange I thought it won't be easy from the beginning :)<br><br>Thanks for the good advice, Matt. I think I will do as you suggest and add this &quot;tracking&quot; part to my sql connection's string. But in such a large system as mine it might take time to create appropriate architecture to cover all cases. But nevertheless it is a solution and I hope it will provide some insight.<br><br>I will post results of the experiment here when I finish. Thanks again.Thu, 19 Mar 2009 08:03:21 Z2009-03-19T08:03:21Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#0044a85f-3126-41ce-bec5-3e651a45ae10http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#0044a85f-3126-41ce-bec5-3e651a45ae10Marcos_Alcantarahttp://social.msdn.microsoft.com/Profile/en-US/?user=Marcos_AlcantaraSQLDataReader.GetOrdinal() fails rarely with IndexOutOfRangeWell, I was reading this whole thread, and I must say that I may have found a solution. My case is not different from anyone's problems. I was occasionally getting a wrong resultset for a well known procedure. That was happening for the last 2 months and came without any warning.<br/> <br/> I read about the possible connection pooling bug and tried to find an answer for this. I then thought If it would be of any help, to clean up the connection right after the .Open method. So I changed my production server's connection strings to add the key/value pair <strong>&quot;;Connection Reset=true&quot;</strong> .<br/> <br/> The InvalidOperationException was happening more than 10 times a minute. And I might say, it <span style="text-decoration:underline">had not</span> happened for the last 1 hour, since I changed the connection strings. And I ought add, that these exceptions did not vanish right away. It took some minutes so it could be completely stopped.<br/> <br/> I will continue to monitor this issue and see if the actual results are being affected by any situation and, in fact, have not been fixed.<br/> <br/> Thanks anyone for the tips.<br/> <br/> Marcos de Barros Alcantara<br/> Flytour Turismo - BrasilThu, 30 Apr 2009 16:47:50 Z2009-04-30T16:47:50Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#8356dac8-b73a-471c-b5ed-5d328a9f3895http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#8356dac8-b73a-471c-b5ed-5d328a9f3895Matt Neerincx [MSFT]http://social.msdn.microsoft.com/Profile/en-US/?user=Matt%20Neerincx%20%5bMSFT%5dSQLDataReader.GetOrdinal() fails rarely with IndexOutOfRangeMarcos, let me know what version of .NET you are using as well as what SQL Server version, thanks!Mon, 04 May 2009 01:12:14 Z2009-05-04T01:12:14Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#f76df603-8593-4582-9543-8f63ee7edcc7http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#f76df603-8593-4582-9543-8f63ee7edcc7Marcos_Alcantarahttp://social.msdn.microsoft.com/Profile/en-US/?user=Marcos_AlcantaraSQLDataReader.GetOrdinal() fails rarely with IndexOutOfRangeHi Matt,<br/> <br/> Thanks for asking. I am using .NET 3.5 and SQL Server 2005 SP1.<br/> <br/> As I have stated before, my results could and were wrong. The pseudo-success was due to low traffic hours. As soon as users begun using the application again, the error was evidenced.<br/> <br/> I am again at zero-point. No ideas for this. Yet, this problem is affecting our production servers and I have no more information, so I can describe more than the others here have already done.<br/> <br/> Do you have any ideas, Matt?<br/> <br/> Thanks!<br/> <br/> Marcos de Barros Alcantara<br/> Flytour Turismo - Brasil<br/> <br/>Mon, 04 May 2009 01:52:26 Z2009-05-04T01:52:26Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#79c7ed71-7025-48e2-ba01-91b439743170http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#79c7ed71-7025-48e2-ba01-91b439743170adivohttp://social.msdn.microsoft.com/Profile/en-US/?user=adivoSQLDataReader.GetOrdinal() fails rarely with IndexOutOfRangeHi Matt, Any progress on this? I'm experiencing the same problem. Thu, 28 May 2009 15:00:40 Z2009-05-28T15:00:40Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#42aa83bf-f188-4800-b8ef-fba7b66c86e5http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#42aa83bf-f188-4800-b8ef-fba7b66c86e5oliver0303http://social.msdn.microsoft.com/Profile/en-US/?user=oliver0303SQLDataReader.GetOrdinal() fails rarely with IndexOutOfRangeAnyone found a solution to this ? Is this a bug in MS connection pool code ?<br/><br/>We have disabled connection pooling and are doing ALOT of hard database connects at the moment, but the problem went away after that, but this can only be a temp. solution.Fri, 29 May 2009 06:16:03 Z2009-05-29T06:16:03Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#a5f64ff3-419e-469b-a2a2-412292805066http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#a5f64ff3-419e-469b-a2a2-412292805066Pedro Rainhohttp://social.msdn.microsoft.com/Profile/en-US/?user=Pedro%20RainhoSQLDataReader.GetOrdinal() fails rarely with IndexOutOfRange<blockquote>Our pooling code is very complex, it has to pool and also be aware of System.Transaction state of threads, manage this with connections to SQL Server, perform transaction escalation when needed, etc...  Also, inside the ASP.NET environment it is very difficult to pool things because ASP.NET uses thread aborts to cancel operations.  You can have a thread in the middle of fetching a resultset from a connection and ASP.NET decides to abort the thread mid-operation.  We added code in .NET 2.0 SP2 (hotfix I described) to attempt to get things back into a clean state when this happens.<br/><br/>Along with this you can have code that is not thread safe using connections after they are disposed for example, this can cause side effects like phantom results.<br/><br/>In general we have not seen a clear cut series of customers reporting phantom results.  When we debug the few of these we've seen in the end it usually turns out to be an application issue like multiple threads using same connection, store procs with conditional logic, etc...<br/><br/>But in any case, I would like to help you get to the bottom of this, whether it's in our code or your code.<br/><br/>First thing you can do for me is partition the pool instead of turning it off.  For example, you can partition your connection strings in different parts of your application to isolate the source of the problem.  This help us isolate the repro code more precisely.<br/><br/>To partition, append a unique keyword to end of your connectiuon strings, for example:<br/><br/>using (SqlConnection conn = new SqlConnection(connectionString + &quot;;Application Name=FunctionName;&quot;))<br/>{<br/>...<br/>}<br/><br/>You don't need to necessarily use a FunctionName level of isolate, you can use for example FileName for example to scope the issue to file scope.<br/><br/>Do this to see which particular files are having the problems, this will help isolate the code to reproduce the problem.   You can then further partition down to function level to isolate which functions are having the impact.<br/><br/>Like the previous poster's mentioned, be sure to clearly deal with SqlConnection, SqlDataReader objects and call Close on them in method scope when possible.  Avoid SqlConnection objects that exceed method scope.  Avoid storing SqlConnection objects as class members, etc...  The general rule is open as late as possible and close as soon as possible, this is most beneficial to pooling performance.<br/><br/><br/><br/></blockquote> <br/>Matt, i'm testing your sample:<br/><br/>using (SqlConnection conn = new SqlConnection(connectionString + &quot;;Application Name=FunctionName;&quot;))<br/>{<br/>...<br/>}<br/><br/><br/>In the application where i'm working on there are places where i'm using sqlconnection directly (And I have errors here) and in the rest of the application i'm using EntLib datablock (and I have errors too in some places). We used to use Entlib 2.0 data block and we made the shift to 4.0 about half a year. I had analysed EntLib code and in entlib 2.0 a connection was always create while in version 4.0 it seems that they only have a connection per connectionString. This pair connectionString, Connection is stored in a dictionary so it can exists only one. <br/><br/>Using sql sonnection and using Data block i'm have errors using both ways.<br/><br/>I'm my case, one of the places where i have problems, I have a stored proc that do a simple select and returns only one row with 3 column. Most of the time the result is ok but sometimes only one row with one column is return. The interesting part is that this row with one column should be returned in another part of the code. Clearly the result were switch.<br/><br/>I've tested with a windows server 2003 and a windows XP Pro both with .net 3.5 with service packs. The sql server 2005 is version 9.00.3239.00, SP2, Enterprise Edition (64-bit).I don't have a clue on how to solve this problem. <br/><br/>Fri, 29 May 2009 16:20:22 Z2009-05-29T16:20:22Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#84f2a196-8502-4010-a919-b88128fce51chttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#84f2a196-8502-4010-a919-b88128fce51cbbzippohttp://social.msdn.microsoft.com/Profile/en-US/?user=bbzippoSQLDataReader.GetOrdinal() fails rarely with IndexOutOfRangeWe experienced this issue too. Our app has very detailed logging. It's evident that SqlDataReader reads a result set left over from the previous query executed on the same connection a couple of seconds ago. It's an Asp.Net HttpHandler. And yes, the SqlConnection object was static. I discovered that a few days ago and figured that could be causing the problem. I fixed that and redeployed the app. The problem has not reoccurred so far, but I'd say we need to wait for at least a month to be sure it's gone. I wish we had load/stress testing scripts.Thu, 04 Jun 2009 17:27:53 Z2009-06-04T17:27:53Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#1d247fb9-284f-4649-bdaf-d1f0ecaa3340http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#1d247fb9-284f-4649-bdaf-d1f0ecaa3340Marzban Doctorhttp://social.msdn.microsoft.com/Profile/en-US/?user=Marzban%20DoctorSQLDataReader.GetOrdinal() fails rarely with IndexOutOfRangeHi bbzippo,<br/> <br/> When you say your SqlConnection object was static, what do you exactly mean by that? And what did you modify to fix this bug?? Can you please post a code example of before and after scenarios???<br/> <br/> Thanks,<br/> Marzban<br/>Mon, 08 Jun 2009 18:23:33 Z2009-06-08T18:23:33Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#d3d11ee4-f57c-4d9b-a8a5-a200463dc8bahttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#d3d11ee4-f57c-4d9b-a8a5-a200463dc8babbzippohttp://social.msdn.microsoft.com/Profile/en-US/?user=bbzippoSQLDataReader.GetOrdinal() fails rarely with IndexOutOfRangeHi Marzban,<br/><br/>Before scenario:<br/><br/> <pre lang="x-c#">class MyHandler: IHttpHandler { //the connection object is only instantiated once private static SqlConnection cnn = new SqlConnetion(&quot;conn string&quot;); public bool IsReusable { //This is Important! get { return false; } } public virtual void ProcessRequest(HttpContext context) { cnn.Open(); try { ExecuteAQueryAndReadResults(); } finally { cnn.Close(); } } }</pre> After scenario:<br/><br/> <pre>class MyHandler: IHttpHandler { public bool IsReusable { //This is Important! get { return false; } } public virtual void ProcessRequest(HttpContext context) { //Connection object is instantiated each time SqlConnection cnn = new SqlConnetion(&quot;conn string&quot;); cnn.Open(); try { ExecuteAQueryAndReadResults(); } finally { cnn.Close(); } } }</pre> I am still not sure if the problem is gone.Mon, 08 Jun 2009 22:30:48 Z2009-06-08T22:33:09Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#60edd89f-ef9c-4b2a-8369-f7dc6fe65b9chttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#60edd89f-ef9c-4b2a-8369-f7dc6fe65b9cMatt Neerincx [MSFT]http://social.msdn.microsoft.com/Profile/en-US/?user=Matt%20Neerincx%20%5bMSFT%5dSQLDataReader.GetOrdinal() fails rarely with IndexOutOfRangeAs a strict rule of thumb if you are storing a SqlConnection object as a member of any class you have already failed.   Welcome to fail.org. :)  Ahh, I'm jest keedding!<br/><br/>The simplest programming rule to remember for SqlConnection is to <strong>use a method local SqlConnection always</strong> and always be sure to <strong>close it in finally block or via a using statement</strong>:<br/><br/>using (SqlConnection conn = new SqlConnection(...))<br/>{<br/><br/><br/>} // &lt;- this takes care of close for you...<br/><br/>-or-<br/><br/>try<br/>{<br/>     SqlConnection conn = new SqlConnection(...);<br/>     conn.Open();<br/>     <br/>}<br/>catch (Exception ex)<br/>{<br/>     ProcessException(ex);<br/>}<br/>finally()<br/>{<br/>     if (null != conn) conn.Close();  // &lt;- Return connection to pool here.<br/>}Tue, 09 Jun 2009 16:38:24 Z2009-06-09T16:38:24Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#a455f8fa-502b-4f37-a240-38d0b6b872cehttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#a455f8fa-502b-4f37-a240-38d0b6b872ceMarzban Doctorhttp://social.msdn.microsoft.com/Profile/en-US/?user=Marzban%20DoctorSQLDataReader.GetOrdinal() fails rarely with IndexOutOfRangeThanks bbzippo... <br/><br/>That helps a lot... I am reassured that the changes I have made to our data access strategy are in the right direction. I was having this problem with our web services that are heavily loaded, and our company had standardized on NHibernate ORM tool for data access from SQL Server. I believe there was a problem with the way we had incorporated NHibernate sessions, which caused the error mentioned in this thread more than 2 to 3 times a day on each of the servers on our web farm. After a lot of person hours of research and trial and error into this issue with no resolution, the company decided to drop NHibernate, and I was tasked to find a suitable replacement. I researched a few open source ORM tools, and even some paid ORM tools. In the end we determined that our apps needed a very little portion of the entire feature set that the professional or open source tools offer. Needless to say, it took me about 3 weeks, but I created a basic ORM tool for internal use from scratch (I even created a MyGeneration template to automate creation of ORM classes to mirror any db schema). Initial testing shows that it works quite well. Of course, I will keep extending its feature set as we need to, but the decision to add new features will depend on absolute need and performance impacts.<br/><br/>Two things I have learned from my research into this error, and my experience with NHibernate...<br/>1. Always connect as late as possible, and release connection as soon as possible. Keeping this advice in mind, the strategy I adopted in my custom ORM tool, is to connect when a query is ready to be executed, and convert the results into a disconnected DataTableReader object, and immediately terminate the connection. Then return the disconnected DataTableReader to the calling app function. This way, you donot have to hold the connection for ransom until you have processed the datareader. At first, I thought the extra step of converting to a disconnected DataTableReader would become a performance issue, but it really is not, since ORM tools generally are not designed or used for manipulating thousands of rows of data anyways.<br/>2. I also learned that the more the feature set and flexibility of an application grows, the more it's performance shrinks. That is why any features I add to our custom ORM tool will have to be weighed against the feature's performance impact. Currently, the same amount of data access in my custom ORM tool is between 3 to 4 times faster than our previous NHibernate solution. That is very encouraging.<br/><br/>Will keep interested parties posted on this as we refactor more of our heavily used apps to this new ORM tool.<br/><br/>Thanks,<br/><br/>Marzban<br/>Tue, 09 Jun 2009 17:21:23 Z2009-06-09T17:21:23Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#f9029530-810c-489b-aa6c-9adbb9fc7039http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#f9029530-810c-489b-aa6c-9adbb9fc7039bbzippohttp://social.msdn.microsoft.com/Profile/en-US/?user=bbzippoSQLDataReader.GetOrdinal() fails rarely with IndexOutOfRangeThanks Matt,<br/><br/>Yes, I've been well aware of the recommended way of using connections and I personally always stick to it. To me it is natural that the scope that executes the transaction is responsible for acquiring and disposing the connection.<br/>However, virtually in every application that I work with, in every other home-grown (or even widely praised) &quot;data access framework&quot; etc. I see violations of this pattern. Developers tend to delegate connection management to another layer just to save two lines of code per data access method.<br/>And the reason is that nobody is aware of any negative consequences. That is in turn caused by the unclear semantics of the SqlConnection constructor and by lack of documentation on connection pooling internals. <br/>Maybe you could explain why exactly we must not reuse connection objects and what exactly happens if we do?<br/><br/>Also please notice that many people in this thread who reported the problem posted perfectly correct code examples. So I'm not 100% sure that the reuse of connections is what's causing it.<br/>Wed, 10 Jun 2009 22:54:46 Z2009-06-10T22:54:46Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#16263999-47c0-4684-a0a2-fc9af2434207http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#16263999-47c0-4684-a0a2-fc9af2434207super315http://social.msdn.microsoft.com/Profile/en-US/?user=super315SQLDataReader.GetOrdinal() fails rarely with IndexOutOfRangeWe have the same error. Could any confirm below things?<br/><br/>In one IIS server, there are two web site which use different application pool. <br/>If we use same connection string in the two web site, if the two web site will use same connection pool though they are in different  application pool?<br/><br/>Thanks,<br/>-BillyThu, 11 Jun 2009 12:54:59 Z2009-06-11T12:54:59Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#4202abd2-34e6-410d-a721-facdd3df58b7http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#4202abd2-34e6-410d-a721-facdd3df58b7Pedro Rainhohttp://social.msdn.microsoft.com/Profile/en-US/?user=Pedro%20RainhoSQLDataReader.GetOrdinal() fails rarely with IndexOutOfRangeMatt I was able to find the problem in my application.<br/> <p class=MsoNormal><span lang=EN-US> <br/> In our code there was a class with a static DbCommand variable inside that is only initialized only one time. Obviously this is a error.<br/> Here is a sample:<br/> <br/> class XXX<br/> static DbCommand command = null;<br/> static CommandText = &quot;dbo.MySP&quot;<br/> static int parameter1 = 1;<br/> static Database db = null;<br/> <br/> static XXX<br/> {<br/>     db = DatabaseFactory.CreateDatabase(DatabaseName);<br/>     command = db.GetStoredProcCommand(CommandText, parameter1);<br/> }<br/> <br/> public int MyResult()<br/> {<br/>     return (int)db.ExecuteScalar(command);<br/> }<br/> <br/> The problem here is that every time the ExecuteScalar is executed, internally EntLib creates a connection and sets the DbCommand.Connection property with a new connection.<br/> <br/> Now, this all might work ok if there was only one thread, but if when we use multiple threads this is a problem.<br/> <br/> I've create a sample application that can replicate this problem and can replicate connections being switched from one command to another. The next sample is wrong, I know, but replicate the problem.<br/> <br/> <br/> here is a sample:<br/> <br/> using System;<br/> using System.Collections.Generic;<br/> using System.Text;<br/> using System.Data.SqlClient;<br/> using System.Data;<br/> using System.Diagnostics;<br/> using System.Threading;<br/> <br/> namespace ConsoleApplication6<br/> {<br/>     class Program<br/>     {<br/>         private static string ConnectionString = &quot;XXXXXXXXXXXXXXXXXXXXXXXXXXX&quot;;<br/>         private static SqlCommand myCommand;<br/> <br/>         static void Main(string[] args)<br/>         {<br/>             for (int i = 0; i &lt; 5; ++i)<br/>             {<br/>                 new Thread(ExecuteMySP1).Start();<br/>             }<br/> <br/>             for (int i = 0; i &lt; 20; ++i)<br/>             {<br/>                 new Thread(ExecuteMySP2).Start();<br/>             }<br/>         }<br/> <br/>         private static SqlCommand GetMySP1Command()<br/>         {<br/>             if (myCommand == null)<br/>             {<br/>                 myCommand = new SqlCommand(&quot;MySP1&quot;);<br/>                 myCommand.CommandType = CommandType.StoredProcedure;<br/> <br/>                 SqlParameter parameterSectionName = new SqlParameter(@&quot;@Param1&quot;, SqlDbType.NVarChar);<br/>                 parameterSectionName.Value = &quot;MyString&quot;;<br/>                 myCommand.Parameters.Add(parameterSectionName);<br/> <br/>                 SqlParameter parameterApplicationId = new SqlParameter(@&quot;@Param2&quot;, SqlDbType.Int);<br/>                 parameterApplicationId.Value = 123;<br/>                 myCommand.Parameters.Add(parameterApplicationId);<br/> <br/>                 SqlParameter parameterMediaId = new SqlParameter(@&quot;@Param3&quot;, SqlDbType.Int);<br/>                 parameterMediaId.Value = 2;<br/>                 myCommand.Parameters.Add(parameterMediaId);<br/>             }<br/> <br/>             return myCommand;<br/>         }<br/> <br/>         private static void ExecuteMySP1()<br/>         {<br/>             for (; ; )<br/>             {<br/>                 <br/>                 using (SqlConnection myConnection = new SqlConnection(ConnectionString))<br/>                 {<br/>                     try<br/>                     {<br/>                         SqlCommand command = GetMySP1Command();<br/>                         command.Connection = myConnection;<br/> <br/>                         // Execute the command<br/>                         myConnection.Open();<br/> <br/>                         using (SqlDataReader reader = command.ExecuteReader())<br/>                         {<br/>                             bool canRead = false;<br/>                             if ((canRead = reader.Read()) &amp;&amp; reader.FieldCount == 3) //should return always 3 columns. else there is a problem<br/>                             {<br/>                                 <br/>                             }<br/>                             else<br/>                             {<br/>                                 Debugger.Break();<br/>                             }<br/>                         }<br/>                     }<br/>                     catch (Exception ex)<br/>                     {<br/>                         Console.WriteLine(ex.Message);<br/>                     }<br/>                 }<br/>                <br/> <br/>                 Thread.Sleep(10);<br/>             }<br/>         }<br/> <br/>         private static void ExecuteMySP2()<br/>         {<br/>             for (; ; )<br/>             {<br/>                 <br/>                 using (SqlConnection myConnection = new SqlConnection(ConnectionString))<br/>                 {<br/>                     try<br/>                     {<br/>                         SqlCommand myCommand = new SqlCommand(&quot;MySP2&quot;, myConnection);<br/>                         myCommand.CommandType = CommandType.StoredProcedure;<br/> <br/>                         SqlParameter parameterHash = new SqlParameter(@&quot;@Param1&quot;, SqlDbType.Int);<br/>                         parameterHash.Value = 1;<br/>                         myCommand.Parameters.Add(parameterHash);<br/> <br/>                         // Execute the command<br/>                         myConnection.Open();<br/> <br/>                         using (SqlDataReader reader = myCommand.ExecuteReader())<br/>                         {<br/>                             bool canRead = false;<br/>                             if ((canRead = reader.Read()) &amp;&amp; reader.FieldCount == 1) //should return always 3 columns. else there is a problem<br/>                             {<br/>                                 <br/>                             }<br/>                             else<br/>                             {<br/>                                 Debugger.Break();<br/>                             }<br/>                         }<br/>                     }<br/>                     catch (Exception ex)<br/>                     {<br/>                         Console.WriteLine(ex.Message);<br/>                     }<br/>                 }<br/>                 <br/> <br/>                 Thread.Sleep(5);<br/>             }<br/> <br/>         }<br/>     }<br/> }<br/> <br/> As you can see in this sample I'm executing 2 SP. <br/> The first should returns 3 columns and the second should return 1 column. Otherwise I will break the application.<br/> <br/> Ignore the exceptions and focus only in this portion of code:<br/> <br/> bool canRead = false;<br/> if ((canRead = reader.Read()) &amp;&amp; reader.FieldCount == 3) //should return always 3 columns. else there is a problem, Sometimes FieldCount is equal to 1, connection switched<br/> {<br/>     <br/> }<br/> else<br/> {<br/>     Debugger.Break();<br/> }<br/>                             <br/> bool canRead = false;<br/> if ((canRead = reader.Read()) &amp;&amp; reader.FieldCount == 1) //should return always 3 columns. else there is a problem, Sometimes FieldCount is equal to 3, connection switched<br/> {<br/>     <br/> }<br/> else<br/> {<br/>     Debugger.Break();<br/> }<br/> <br/> <br/> Somehow when I'm executing a command in a connection, that connection is being switched to another command.<br/> <br/> In this case you will see that sometimes the application will hit Debugger.Break(); with 1 column instead of 3 columns and others with 3 columns instead of 1 column. Again the connections are switched.<br/> <br/> What I was expecting, in a very simple way, was that each command every time is executed in a connection mark that connection with a ID X and when the result came back <br/> the command with ID X will have the result from connection with ID X I imagine that is much more complicated and is resulting in connections being switched. <br/> <br/> You can perhaps use this code in order to try find a problem in the framework that solve the problem of every body in this thread :)</span></p>Mon, 15 Jun 2009 16:11:59 Z2009-06-15T16:21:29Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#b0e6dc2a-1200-450e-abea-af3678dc8108http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#b0e6dc2a-1200-450e-abea-af3678dc8108Raghav Nayakhttp://social.msdn.microsoft.com/Profile/en-US/?user=Raghav%20NayakSQLDataReader.GetOrdinal() fails rarely with IndexOutOfRangeDear All, <br/><br/>We had migrated our web application from 1.1 to 2.0. Our application was working absolutely fine in our local server. When we deployed the application on the production server on 1st of this month, we started getting the errors given below. <br/><br/>Object reference not set to an instance of an object. <br/><br/>Index was outside the bounds of the array. <br/><br/>Specified cast is not valid. <br/><br/>Unable to cast object of type 'System.Int32' to type 'System.String'. <br/><br/>Column 'UserID' does not belong to table Table <br/><br/>Could not find prepared statement with handle 1716 <br/><br/>That too these errors would come once in every 2-3 hrs. We had to recycle our application pool. This annoyed our customers as it would log out the application. <br/>They started complaining as its obvious with anyone when they lose their work. <br/><br/>We tried all the possibilities. We checked for connection leak, dbHelper component, even tried to change the session state. <br/>Finally, last week I found this article. Got relief reading that many people are facing the same problem. <br/><br/>Some recommended temporary solution to turn off the connection pool. Even though this would hit the performance, we din't have any other options. We turned the connection pool off on monday, this week. <br/><br/>Good news is that since then we have not seen the above errors. On an average we would recycle the application pool 4-5 times a day. <br/><br/>Even though this solution has given us some relief, we can't compromise with the application performance. We need to find a permanent solution so that we can turn on the pool back. <br/>Please let me know if anyone would like to help me. <br/><br/>Thanks &amp; Regards, <br/>RaghavTue, 16 Jun 2009 14:03:20 Z2009-06-16T14:06:09Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#e2529d63-f604-435f-be85-5799e47c13bchttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#e2529d63-f604-435f-be85-5799e47c13bcMarcos_Alcantarahttp://social.msdn.microsoft.com/Profile/en-US/?user=Marcos_AlcantaraSQLDataReader.GetOrdinal() fails rarely with IndexOutOfRangeMatt Neerincx should not have marked bbzippo's post as answer since it´s not the main problem here. It was indeed a great contribution from bbzippo, but still not the main focus.<br/> <br/> The question remains unanswered. The SQL Server 2005 still returns wrong results once in a while and we still doesn´t have the appropriated support.<br/> <br/> Matt, can you please invoke some more powerful helpers from your support team to help us investigate the problem?<br/> <br/> We are beginning to have some negative feedback from our customers and that´s very annoying for us as Microsoft certified partners.<br/> <br/> Thanks and best regards,<br/> <br/> Marcos de Barros Alcantara<br/> Flytour Turismo / Envision Tecnologia<br/> São Paulo - Brazil<br/> <br/>Tue, 16 Jun 2009 14:17:04 Z2009-06-16T14:17:04Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#b2af071e-1422-4a97-97cb-b32a28d6f757http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#b2af071e-1422-4a97-97cb-b32a28d6f757oliver0303http://social.msdn.microsoft.com/Profile/en-US/?user=oliver0303SQLDataReader.GetOrdinal() fails rarely with IndexOutOfRangeMicrosoft really needs to look into this ugly bug. Obviously the only resolution found so far is to disable connection pooling, which we have also done, but this is not a solution.<br/><br/>We never experineced this on our windows 2003, sql server 2005 servers. We moved to windows 2008 64bit and sql server 2008 and all ____ broke loose. Excatly the same problems like everyone else are experincing.<br/><br/>We have even talked to microsoft support, but the only solution they could come up with, was to do memory dumps on our production platform when we had the problems, which we are not interested in, as customers was beginning to get very very upset, so when the temp bugfix with disabling connection pooling was mentioned we inplemented that. We cannot afford to present customers with recordsets from other customers, recycling asp.net pool etc etc, for them to have memorydumps.<br/><br/>Is this a 64bit problem ?Tue, 16 Jun 2009 15:16:01 Z2009-06-16T15:16:01Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#482cfa3d-940f-4be3-aaf7-b0aaa9d94b85http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#482cfa3d-940f-4be3-aaf7-b0aaa9d94b85Pedro Rainhohttp://social.msdn.microsoft.com/Profile/en-US/?user=Pedro%20RainhoSQLDataReader.GetOrdinal() fails rarely with IndexOutOfRangeMarcos I've post a sample yesterdey here that show that it's possible to switch results ramdomly, of course I think this is a error. Results should never be switched. <br/> I really hope matt or someone at MS try the sample and I hope they find the problem of switched results... <br/> <br/> In my case took me 7 days to find my problem in a huge application I work on.<br/> <br/> It's impressive that the first post was inserted in 2005 and no solution :(Tue, 16 Jun 2009 15:26:28 Z2009-06-16T15:26:28Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#b65c1f99-abfb-457c-b637-7c093c225ba2http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#b65c1f99-abfb-457c-b637-7c093c225ba2Marcos_Alcantarahttp://social.msdn.microsoft.com/Profile/en-US/?user=Marcos_AlcantaraSQLDataReader.GetOrdinal() fails rarely with IndexOutOfRangeHi Oliver,<br/> <br/> Thanks for mention the version you are having these symptons.<br/> <br/> In my case it still is a Windows Server 2003 and Sql Server 2005.<br/> <br/> With your post, it just seems to me that the problem persists in the newer version of Sql Server and that is not really a good sign of progress from MS.<br/> <br/> Microsoft support have done some memory dumps in our production server too and I don´t see where that info can get them.<br/> <br/> I don´t see a light at the end of the tunnel. We are in the dark here.<br/> <br/> Hope we can get some attention from the senior support guys.<br/> <br/> Thanks for sharing!<br/> <br/> Marcos de Barros Alcantara<br/> Flytour Turismo / Envision Tecnologia<br/> São Paulo - BrazilTue, 16 Jun 2009 15:28:57 Z2009-06-16T15:28:57Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#ee23833f-3a1b-4f7e-9488-a4cd5ff254f1http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#ee23833f-3a1b-4f7e-9488-a4cd5ff254f1Matt Neerincx [MSFT]http://social.msdn.microsoft.com/Profile/en-US/?user=Matt%20Neerincx%20%5bMSFT%5dSQLDataReader.GetOrdinal() fails rarely with IndexOutOfRangeI sure wish there was a smoking gun here but we have millions of customers using SqlClient and ASP.NET without hitting these exceptions.  I suspect if there was a fundamental flaw in pooling or SqlClient we would see a much higher prevalence of this issue with our customers.<br/><br/>In any case I am happy to help debug if you have this issue to ensure we are not missing anything.   I think the quickest way to debug this would be to open a support case and get them to help debug the web server, I can be called in to assist support, they know me.   If anyone can put together a reproducible scenario for this that would be best of course.<br/><br/>Note when moving to newer HW like 64-bit did you also increase the number of CPUs?  Increasing numbers of CPUs will aggrevate existing threading bugs.<br/><br/>This morning I spent an hour reviewing internal customer support cases I have seen the following root causes:<br/><br/>1. Customer just mistakely left out field names from select statement.<br/>2. Customer calling stored procedure with conditional logic (sometimes would select one statement, sometimes another).<br/>3. Customer using non-method scoped SqlConnections (SqlConnection stored in member variable for example), hence multi-threaded access can occur.<br/>4. Customer using older version of DAAB Enterprise Library that mistakely uses static SqlConnection (and thus is not thread safe).<br/><br/>Note from reviewing the case logs I have seen this issue reported to our support teams over and over for years and in every single case our support team worked very hard with the customer to debug the root cause, gathering crash dumps, etc... and in every case thus far it has been a customer coding issue.<br/><br/>Note it appears older versions of DAAB had some problems so if you are using DAAB be sure to download latest version.Tue, 16 Jun 2009 17:21:08 Z2009-06-16T17:21:08Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#c2134b7b-648c-406e-a34d-84a110d40b2fhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#c2134b7b-648c-406e-a34d-84a110d40b2fMatt Neerincx [MSFT]http://social.msdn.microsoft.com/Profile/en-US/?user=Matt%20Neerincx%20%5bMSFT%5dSQLDataReader.GetOrdinal() fails rarely with IndexOutOfRangeAlso, read back in the history of this posting, we have already seen many of the customers hit this because of using static SqlConnection/SqlCommand objects.  Hence I would not say this long running issue was in vain, customers are solving problems using this post.Tue, 16 Jun 2009 17:45:05 Z2009-06-16T17:45:05Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#4c158466-de5b-429d-9fd3-93eddd68ab8chttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#4c158466-de5b-429d-9fd3-93eddd68ab8cMarcos_Alcantarahttp://social.msdn.microsoft.com/Profile/en-US/?user=Marcos_AlcantaraSQLDataReader.GetOrdinal() fails rarely with IndexOutOfRangeMatt,<br/> <br/> Thanks for the time to answer these last replies.<br/> <br/> I'm glad people are finding this post useful. I'm also sure your search into internal customer support really told you something. A lot of people are making those mentioned mistakes and through this post they are being able to correct their applications.<br/> <br/> Glad, also, because this issue is happening only to a small group of customers.<br/> <br/> Although, our case is not being listed. It seems to be a more grotesque problem.<br/> <br/> Everyone who has this problem has mentioned the following:<br/> <br/> 1. Their connection's object is within scope.<br/> 2. They are opening and closing inside the same method and inside a try/catch block.<br/> 3. There is not any conditional elements regarding to the procedures.<br/> 4. The same code block executes hundreds of times without any problem.<br/> 5. The same code block that executes fine for hundreds of times, then returns a wrong resultset and the reader seems corrupted.<br/> 6. Some people turned their connection pooling feature off and saw the problem vanish.<br/> <br/> <br/> Reading this post, one must be careful not to confuse himself. There is a lot of related problems, but 90% didn't catch the real one.<br/> <br/> For instance, that's all I've got. <br/> <br/> Thanks Matt, for your time. I know this problem is no piece of cake, just by seeing this post's timeline. (4 years).<br/> <br/> If you can think in anything to help us debug and investigate more deeply, it's going to be of greater help.<br/> <br/> Best regards,<br/> <br/> Marcos de Barros Alcantara<br/> Flytour Turismo / Envision Tecnologia<br/> São Paulo - BrazilTue, 16 Jun 2009 18:03:28 Z2009-06-16T18:03:28Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#8097bc33-ab26-49d2-b933-620adee94daehttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#8097bc33-ab26-49d2-b933-620adee94daeMatt Neerincx [MSFT]http://social.msdn.microsoft.com/Profile/en-US/?user=Matt%20Neerincx%20%5bMSFT%5dSQLDataReader.GetOrdinal() fails rarely with IndexOutOfRangeJust as an experiment I wrote a quick multi-threaded app to replicate the problem with static SqlConnections.<br/>Very quickly I am able to generate the target exception on my quad proc 64-bit machine.<br/><br/><strong>The key find from this experiment is that your specific code in one place may be safe</strong> but other code in the same process that is not safe can corrupt the state of SqlConnections in the pool.  If you run the code sample you will note that &quot;safe&quot; threads are getting the IndexOutOfRangeExceptions.<br/><br/>Hence a probable cause of these issues is some other code in your process that is improperly using pooled connections over multiple threads.<br/><br/><strong>A sugggestion I made earlier to solve this issue (or at least isolate it) thus still holds:</strong>  Add <strong>Application Name=X</strong> to your connection strings to &quot;partition&quot; your pools.  You can use any value you want for X, you can use the current thread's ID for example to partition pools by thread id, you can use filename, you can use function name, etc...  Once you partition then you can isolate (divide and conquer) which remaining parts of the code are corrupting the pool and the rest of your code that uses other pool partitions will be 100% safe from the bad code.<br/><br/>You will note from the code example below, only one thread in 5 will share the global connection globalConn.  Each thread runs a different select statement based on the thread id and then attempts to read the field name expected.  You will need to modify the connection string to point to your SQL Server but the sample does not rely on any pre-created tables to run (it just selects expression value).<br/><br/><br/> <pre lang="x-c#">using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using System.Data.SqlClient; namespace PoolCorrupt { class Program { static void Main(string[] args) { int threadCount = 100; for (int i = 1; i &lt;= threadCount; i++) { new Thread(new ThreadStart(Program.WorkerThread)).Start(); } } static int tidCounter = 0; static UInt32 value = 0; static SqlConnection globalConn = null; static SqlConnection GetConn(string connect, bool useGlobalConn) { SqlConnection connLocal = null; if (useGlobalConn) { connLocal = globalConn; if (null == connLocal) { connLocal = new SqlConnection(connect); connLocal.Open(); globalConn = connLocal; return connLocal; } else { return connLocal; } } else { connLocal = new SqlConnection(connect); connLocal.Open(); return connLocal; } } static object consoleLock = new object(); static void WorkerThread() { int tid = Interlocked.Increment(ref tidCounter); string select = string.Format(&quot;select {0} as [f{1}]&quot;, tid, tid); string fieldName = string.Format(&quot;f{0}&quot;, tid); string connect = &quot;server=MySqlServer;user id=test;password=test;&quot;; int readCount = 0; bool useGlobalConnThread = (0 == (tid % 5)); SqlConnection conn = null; SqlCommand cmd = null; SqlDataReader dr = null; for (;;) { try { conn = GetConn(connect, useGlobalConnThread); cmd = conn.CreateCommand(); cmd.CommandText = select; cmd.CommandTimeout = 5; dr = cmd.ExecuteReader(); dr.Read(); int fieldValue = (int)dr[fieldName]; System.Diagnostics.Debug.Assert(fieldValue == tid); readCount++; if (0 == (readCount % 2500)) { Console.WriteLine(&quot;Thread{0} reads{1}&quot;, tid, readCount); } } catch (IndexOutOfRangeException iorEx) { lock (consoleLock) { Console.WriteLine(&quot;Caught targeted exception IndexOutOfRangeException:&quot;); Console.WriteLine(&quot;expected -&gt; {0}&quot;, fieldName); Console.WriteLine(&quot;actual -&gt; {0}&quot;, dr.GetName(0)); if (useGlobalConnThread) { Console.WriteLine(&quot;Ok, I'm a bad thread and I'm sharing SqlConnections, I know this is going to happen.&quot;); } else { Console.WriteLine(&quot;Hey, I'm a safe thread and just a victim!&quot;); System.Diagnostics.Debug.Assert(false); } } } catch (Exception ex) { lock (consoleLock) { Console.WriteLine(ex.Message); if (useGlobalConnThread) { Console.WriteLine(&quot;Ok, I'm a bad thread and I'm sharing SqlConnections, I know this is going to happen.&quot;); } else { Console.WriteLine(&quot;Hey, I'm a safe thread and just a victim!&quot;); } // Reset globalConn on failure. SqlConnection connLocal = GetConn(connect, false); SqlConnection connToClose = globalConn; globalConn = connLocal; try { connToClose.Close(); } catch (Exception) { }; } } finally { if (!useGlobalConnThread) { if (null != conn) conn.Close(); } if (null != cmd) cmd.Dispose(); if (null != dr) dr.Close(); conn = null; cmd = null; dr = null; } } } } } </pre>Tue, 16 Jun 2009 19:11:57 Z2009-06-16T19:11:57Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#9984f152-8b0f-4b5b-93a4-1ce8c121d5eahttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#9984f152-8b0f-4b5b-93a4-1ce8c121d5eaoliver0303http://social.msdn.microsoft.com/Profile/en-US/?user=oliver0303SQLDataReader.GetOrdinal() fails rarely with IndexOutOfRange<p>Thank you Matt for sharing this. We have tried many many things and have had more experienced developers and MS support team to look at our code to no help.<br/><br/>We DO use DAAB Enterprise library, and the latest version 4.1 from oct. 2008, and the latest framework version 3.5. Using ent lib we thought would help us from hitting erros like this as long as we encaptulate our readers into <br/><br/>while (DBReader.Read) and disposing and closing everything immidiatly after usage.</p>Tue, 16 Jun 2009 20:34:17 Z2009-06-16T20:34:17Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#43844ab3-e745-4517-8556-bd96ed1febf8http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#43844ab3-e745-4517-8556-bd96ed1febf8Matt Neerincx [MSFT]http://social.msdn.microsoft.com/Profile/en-US/?user=Matt%20Neerincx%20%5bMSFT%5dSQLDataReader.GetOrdinal() fails rarely with IndexOutOfRangeThe thing to remember is the connection pool is a process wide pool<strong> and the key to the pool is your connection</strong> <strong>string</strong>.<br/><br/>Other code in the same process could potentially do bad things with pooled connections (multi-threaded use) and break otherwise perfectly good code in other parts of the process.<br/><br/>You can partition your pool usage by making your connection string unique in some fashion, for example using the Application Name=X trick described above, this will ensure your code has it's own unique pool, this will at least help you isolate the issue down to the offending code.Tue, 16 Jun 2009 22:49:13 Z2009-06-16T22:49:13Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#282c466e-2629-4db6-b9f6-cf74d4ecf8f5http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#282c466e-2629-4db6-b9f6-cf74d4ecf8f5bbzippohttp://social.msdn.microsoft.com/Profile/en-US/?user=bbzippoSQLDataReader.GetOrdinal() fails rarely with IndexOutOfRangeMatt, thank you very much, this explains a lot. But I am still curious how exactly the pool gets corrupted when we reuse connections? Is this purely a concurrency issue or something else?Wed, 17 Jun 2009 12:19:37 Z2009-06-17T12:19:37Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#1f0f776c-311d-4987-bfb7-f9918ee73436http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#1f0f776c-311d-4987-bfb7-f9918ee73436bbzippohttp://social.msdn.microsoft.com/Profile/en-US/?user=bbzippoSQLDataReader.GetOrdinal() fails rarely with IndexOutOfRangeMatt, another question. You wrote &quot;the connection pool is a process wide pool&quot;. I thought it was appdomain wide. For Asp.Net it makes a big difference. Could you please confirm? Wed, 17 Jun 2009 13:19:04 Z2009-06-17T13:19:04Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#97c86c59-7359-4887-998e-0eb56f8a1813http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#97c86c59-7359-4887-998e-0eb56f8a1813Matt Neerincx [MSFT]http://social.msdn.microsoft.com/Profile/en-US/?user=Matt%20Neerincx%20%5bMSFT%5dSQLDataReader.GetOrdinal() fails rarely with IndexOutOfRangeYes you are correct it is app domain wide and not process wide.<br/>Hence each app domain will be isolated from other app domain pools.<br/><br/>That brings up a good point you can also use app domain isolation to partition application code to determine which code is corrupting the pool as well, I did not think of that one.Wed, 17 Jun 2009 16:42:20 Z2009-06-17T16:42:20Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#c347b6c8-f039-4fa2-a917-e546efbe6331http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#c347b6c8-f039-4fa2-a917-e546efbe6331Matt Neerincx [MSFT]http://social.msdn.microsoft.com/Profile/en-US/?user=Matt%20Neerincx%20%5bMSFT%5dSQLDataReader.GetOrdinal() fails rarely with IndexOutOfRangeIn response to:<br/><br/> <div class=body>Matt, thank you very much, this explains a lot.<strong> But I am still curious how exactly the pool gets corrupted when we reuse connections?</strong> Is this purely a concurrency issue or something else?<br/><br/>Here is what I see happening (from looking at network traces etc..) from my repro:<br/><br/>Suppose you have 2 threads using a single SqlConnection over multiple threads concurrently.   What can happen is thread1 is in the process of sending some query, it is deep into our stack at point where it is about to write the select statement to server.  Meanwhile thread2 closes connection, sending it back into pool.   When we close the connection we flush state, but there is no pending state.   Connection starts to return back to pool and thread1 sends command.   Pooled connection immediate gets handed out to a new caller on thread3, this caller now has a pending response waiting from thread1.   If thread3 sends a request and then calls SqlDataReader.read they get thread1's response.<br/><br/>Note the interesting part here is IF you enable MultipleActiveResultsets (MARS) this behavior actually would be avoided since with MARs enabled each request has a special ID so each thread will get only the response they sent.   However enabling MARS is not a good solution to patch a threading bug in your code because with MARs you could have thread1 rolling back transaction for thread2 silently (for once example).  I don't recommend using MARs to patch this one, it has it's own set of dangers the real fix is locate threads that are using SqlConnections concurrently and fix this code.</div>Wed, 17 Jun 2009 16:59:17 Z2009-06-17T16:59:17Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#d75af409-8134-46ab-85aa-58d72a3e1765http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#d75af409-8134-46ab-85aa-58d72a3e1765bbzippohttp://social.msdn.microsoft.com/Profile/en-US/?user=bbzippoSQLDataReader.GetOrdinal() fails rarely with IndexOutOfRangeMatt, thank you again. Your explanation really helps, I appreciate it.Wed, 17 Jun 2009 18:31:53 Z2009-06-17T18:31:53Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#51b31710-277e-47d7-9476-cc4e1a1b6146http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#51b31710-277e-47d7-9476-cc4e1a1b6146Pedro Rainhohttp://social.msdn.microsoft.com/Profile/en-US/?user=Pedro%20RainhoSQLDataReader.GetOrdinal() fails rarely with IndexOutOfRangeMatt, thanks on your explanation on how sql connections and pool are used, it's very usefull also I want to ask if you know a good article that explains it in more detail... <br/> <br/> just to everybody here I did use matt trick Application Name=X to try isolate my problem, I was debugging my app during 5 days and no clue on what could cause the problem, until I found this thread. After try matt trick it took me 1 day to find my problem and solve it. <br/> <br/> Also because our code is separated in modules and each module that uses sql could potencially have it's own DB and it's own connection string, so it was very easy to apply matt trick :).<br/> Where I'm working on It's a huge app and since the code was breaking in too many places it took me a while to find the problem in a static sqlCommand, also took me a while because I had to see what EntLib was doing on create connections and using commands etc...etc...<br/> <br/> Again thanks<br/>Thu, 18 Jun 2009 09:22:01 Z2009-06-18T09:22:01Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#14a85928-b963-4d33-b673-99289155a026http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#14a85928-b963-4d33-b673-99289155a026oliver0303http://social.msdn.microsoft.com/Profile/en-US/?user=oliver0303SQLDataReader.GetOrdinal() fails rarely with IndexOutOfRangePedro, did you find anything specific within the newest 4.1 ent lib which caused this problem ? We use ent lib 4.1 and experience the same thing.Thu, 18 Jun 2009 09:34:44 Z2009-06-18T09:34:44Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#ca8ad134-546e-4184-8906-e7301405315bhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#ca8ad134-546e-4184-8906-e7301405315bPedro Rainhohttp://social.msdn.microsoft.com/Profile/en-US/?user=Pedro%20RainhoSQLDataReader.GetOrdinal() fails rarely with IndexOutOfRangeNo, our problem was not in entlib was in our code.<br/> <br/> We declared a static dbcommand and each time we did Database.ExecuteScalar(command) a new connection was created. now in single thread this might not have been a problem but in multi-thread scenary this is a problem...<br/> <br/> And to prove that I had previouly posted a sample where I use static command in mulit-thread and I was able to switch results across connections...<br/> <br/> just follow this provided by matt<br/> <br/> using (SqlConnection conn = new SqlConnection(...))<br/> {<br/> <br/> <br/> } // &lt;- this takes care of close for you...<br/> <br/> -or-<br/> <br/> try<br/> {<br/>      SqlConnection conn = new SqlConnection(...);<br/>      conn.Open();<br/>      <br/> }<br/> catch (Exception ex)<br/> {<br/>      ProcessException(ex);<br/> }<br/> finally()<br/> {<br/>      if (null != conn) conn.Close();  // &lt;- Return connection to pool here.<br/> }<br/> <br/> and you will have no problems...<br/> <br/> I imagine it's hard to find the problem it took me 7 days just to see that stupid static line :P<br/> <br/> my recomendations is to check all code for static variables and see if you find the problem.Tue, 23 Jun 2009 18:26:37 Z2009-06-23T18:26:37Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#45d44363-9a4b-4b01-a1b6-5b116d92ce0fhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#45d44363-9a4b-4b01-a1b6-5b116d92ce0fbbzippohttp://social.msdn.microsoft.com/Profile/en-US/?user=bbzippoSQLDataReader.GetOrdinal() fails rarely with IndexOutOfRangeHi, I think my message should not have been marked as Answer. The forum now moves messages marked as Answer to the top of the thread and my message now appears out of context. I wasn't replying to the original poster, I was just clarifying my prior message. Moderators, please unmark it, if possible. It will make the tread easier to follow. Thanks. Sat, 27 Jun 2009 08:04:15 Z2009-06-27T08:04:15Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#37232b8f-c616-435b-9018-eb0b425215d1http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#37232b8f-c616-435b-9018-eb0b425215d1Matt Neerincx [MSFT]http://social.msdn.microsoft.com/Profile/en-US/?user=Matt%20Neerincx%20%5bMSFT%5dSQLDataReader.GetOrdinal() fails rarely with IndexOutOfRangeHello folks,<br/><br/><strong>If you are using Entlib</strong> I recently uncovered a <strong>potential</strong> problem (not yet verified) that could trigger this <span style="color:#ff0000">IndexOutOfRangeException.<br/></span><br/><br/>If you examine Entlib code you will see a TransactionScopeConnections class internally.  It is activated when you execute something in Entlib <strong>inside a TransactionScope.</strong><br/><br/>TransactionScopeConnections class attaches an event handler to the ambient transaction and this event handler fires when the transaction completes (either successfully or failing).<br/><br/>When transaction aborts on server side, this event can be triggered asychronously to client while the primary thread of execution in client code is still running (blocked waiting for response).<br/><br/>The event closes the connection, this can happen on 2nd thread while primary thread is in the middle of using the connection, corrupting the connection state.<br/>Corrupted connection is placed back in pool and can be reused by another thread and trigger the IndexOutOfRangeException.<br/><br/>Note however I am still debugging this the evidence is tentative may not be 100% accurate, just a heads up.Thu, 27 Aug 2009 23:49:52 Z2009-08-27T23:49:52Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#76e6106d-72bf-4332-ac8f-76dccc678af4http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#76e6106d-72bf-4332-ac8f-76dccc678af4oliver0303http://social.msdn.microsoft.com/Profile/en-US/?user=oliver0303SQLDataReader.GetOrdinal() fails rarely with IndexOutOfRangeHi Matt,<br/><br/>This sounds very interesting. Thank you very much for keeping us posted on your findings regarding this problem.<br/><br/>You previously wrote that you work within MS consulting. How would we be able to get in contact with you ?Fri, 28 Aug 2009 06:18:10 Z2009-08-28T06:18:10Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#8ec8cee3-5d41-4816-9b2d-eb548e1bb6e7http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#8ec8cee3-5d41-4816-9b2d-eb548e1bb6e7Matt Neerincx [MSFT]http://social.msdn.microsoft.com/Profile/en-US/?user=Matt%20Neerincx%20%5bMSFT%5dSQLDataReader.GetOrdinal() fails rarely with IndexOutOfRangeI'm a developer for SQL Server team, not MS consulting.   You can contact me directly at <a href="mailto:mattn@microsoft.com">mattn@microsoft.com</a>, tx.Fri, 28 Aug 2009 23:40:42 Z2009-08-28T23:40:42Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#f3492089-9e72-4334-8c5f-f5e1f983aed7http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#f3492089-9e72-4334-8c5f-f5e1f983aed7maicanhttp://social.msdn.microsoft.com/Profile/en-US/?user=maicanSQLDataReader.GetOrdinal() fails rarely with IndexOutOfRangeHi,<br/> I have problems only when my users start generating reports (Reporting Services, 2005 Standard). Is there a way to check if there are problems with this as in the post above regarding the EntLib? <br/> Please note that we use DotNetNuke as application framework and it does not have any problems but my app. developed over it has.<br/> <br/> CatalinWed, 23 Sep 2009 05:34:17 Z2009-09-23T05:34:17Zhttp://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#c7394886-f071-406c-9362-699b82bf3144http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9#c7394886-f071-406c-9362-699b82bf3144Matt Neerincx [MSFT]http://social.msdn.microsoft.com/Profile/en-US/?user=Matt%20Neerincx%20%5bMSFT%5dSQLDataReader.GetOrdinal() fails rarely with IndexOutOfRangeThe key point I make is your code can easily be the victim of other code in the same process.  The EntLib issue I have found is a viable issue if you are using Entlib and TransactionScope and you are using SQL 2000 or earlier, so it's a narrow use case.   I had one customer I was working with where we removed EntLib in this case and their problems went away.  But given the specific scenario I have not found a way to reproduce it here at MSFT, so I cannot completely blame EntLib without clear evidence.  Also, I'm working with EntLib team to ensure this is addressed in future versions.Fri, 25 Sep 2009 20:23:20 Z2009-09-25T20:23:20Z