System.IndexOutOfRangeException on a webfarm
Here is another issue that a customer had that I thought would be helpful to others.
Problem
The customer said they are getting Exception type: System.IndexOutOfRangeException every minute or so when accessing their web site. The error looks like:
System.IndexOutOfRangeException: Index was outside the bounds of the array.
at System.Web.UI.WebControls.GridView.LoadControlState(Object savedState)
at System.Web.UI.Control.LoadControlStateInternal(Object savedStateObj)
at System.Web.UI.Page.LoadAllState()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
Resolution
This is trying to load ViewState. ViewState is not necessarily compatible between different versions of the runtime, including service pack changes. A given application, even if distributed in a web farm, must be running on the same exact runtime version on all servers. This includes the bit-ness. So they all need to be x86 or x64 as on the same version (Service Pack, etc).
Comments
Anonymous
August 26, 2008
It gives An Exception for System.IndexOutOfRangeException: Sql Field IS int also. Could You Help ME totalsponsoe = Convert.ToInt32(sdr["AppMstSponsorTotal"]);Anonymous
September 16, 2008
There's probably a typo in your field name.Anonymous
September 16, 2008
Good point Rob, remember that the SQL field names are case sensative.Anonymous
October 13, 2008
my problem is similar to Ramendra Kumar, but i only get the System.IndexOutOfRangeException if i try to call <b>char</b> or <b>text</b> data type from SQL. other fields using int or varchar no problem. i've checked over and over the field name. bceData.Answer = sqlDataReader["AnswerField"].ToString(); the "AnswerField" is <b>text</b> datatype in SQL. can you help me please? i have no permission to alter the database.Anonymous
October 15, 2008
alright, please forget my previous comment :D the problem was in the stored procedure :D now everything is solved :D i'm still learning anyway :DAnonymous
July 27, 2009
sql = "select Rlens_code,Llens_code from Spects where " & oprator & " = '" & Search & "'" CM = New SqlCommand(sqlstr, frmMasterObj.cn) Dim dr1 As SqlDataReader = CM.ExecuteReader If dr1.HasRows = True Then While (dr1.Read) If dr1("Llens_code") = "" Then lblRtLensRef.Text = "" Else lblLtLensRef.Text = dr1("Llns_code").ToString() End If If dr1("Rlens_code") = "" Then lblLtLensRef.Text = "" Else lblRtLensRef.Text = dr1("Rlens_code").ToString() End If End While dr1.Close() End If in this code if some value is null so how can we catch that null value