Intermittent IndexOutOfRangeException - SqlDataReader

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi All

I've been searching on the internet more than a week for a solution to this problem. All that I got was some desperate guys like me without an answer. My ASP.Net system works fine 99% of the time. However, eventually the system starts to fail with an IndexOutOfRangeException in any query that I run using the datareader object. The only way to stop this behavior is restarting the IIS Service. I know it´s not a scalabillity problem... just few users are operating the system on that moment. It could be a pooling problem?

I'll aprecciate any clue
Alisso

[IndexOutOfRangeException: field_name
System.Data.Common.FieldNameLookup.GetOrdinal(String fieldName) +5
System.Data.SqlClient.SqlDataReader.GetOrdinal(String name) +7
System.Data.SqlClient.SqlDataReader.get_Item(String name) +1
 
Allison:

Are you saying that the exact same query runs with the exact same parameters
most of the time, then every instance of a datareader you use gives you an
index out of range exception everywhere?

At first this really sounds like a usage problem and using the GetOrdinal
method for instance, something like changing the alias so it's not found or
some similar usage issue.

But if you are positive that the exact query is being used and the exact
same parameters are being passed, then it's defintely weird indeed. I'll
look around and see if I can find anything out there...I can almost
guarantee that if the exact same stuff works all the time and then all of
your readers start casuing this problem, something weird indeed is
happening. The fact restarting IIS changes this does seem to complicate it,
unless it's some other usage issue and this is masking it.

If you try catch this block, will dr.Read and the like all work? Or do all
datareader operations fail?

--
W.G. Ryan MVP Windows - Embedded

http://forums.devbuzz.com
http://www.knowdotnet.com/dataaccess.html
http://www.msmvps.com/williamryan/
Alisson Vale said:
Hi All,

I've been searching on the internet more than a week for a solution
to this problem. All that I got was some desperate guys like me without an
answer. My ASP.Net system works fine 99% of the time. However, eventually
the system starts to fail with an IndexOutOfRangeException in any query that
I run using the datareader object. The only way to stop this behavior is
restarting the IIS Service. I know it´s not a scalabillity problem... just
few users are operating the system on that moment. It could be a pooling
problem?
I'll aprecciate any clue,
Alisson

[IndexOutOfRangeException: field_name ]
System.Data.Common.FieldNameLookup.GetOrdinal(String fieldName) +55
System.Data.SqlClient.SqlDataReader.GetOrdinal(String name) +70
System.Data.SqlClient.SqlDataReader.get_Item(String name) +10
 
Hi William

Thanks a lot for the answer... I´ll try to clarify you about my problem. Let´s see

Exactly. You've got the point... The application workd fine for two or three days... suddenly every query runned by the sqldatareader starts to fail with this exception (Even a simple login method). Then I have to restart the IIS Service to bring the application to life again

I really don´t believe in a usage problem... the application wouldn´t work in this case and an IIS restart wouldn´t bring it back to life

Ye... I´m sure is the same query... I verified this logging all my queries on a txt file... and it´s all ok
I think your suspicious is correct: something very weird is going on. As I said, I´ve found some messages on the internet describing the same symptoms... the most weird is none of them were answered.

Just this operation fail... the Read() method is executed normally. When a ordinal number is used, everything works fine too
I´ll try this today... Look, my first try was

Change this: myReader[columnName
To this: myReader[myReader.GetOrdinal(columnName)

I suspected it could be a bug in using only the index (case sensitive for example)... but the problem persists

Today... I´ve changed the code to not use the GetOrdinal method (the exception is throwned in this method

string col
int indexCol = -1
for (int i = 0; i <= myReader.FieldCount; i++

col = myReader.GetName(i)
if (col.ToUpper() == columnName.ToUpper()

indexCol = i
break
}


return myReader[indexCol]

Now... I´m waiting to see if the problem happen again...

Please, if you think in some possibility let me know

Regards
Alisso
 
I have the exact same problem, and the only clue I have come across is
that sometimes this occurs on datagrids when the data has changed
between the time you get the data and the time you sort it.

strSQL = "Field= '" & strCriteria & "'"
myRows = Me.dsStatus.Tables(0).Select(strSQL,
"SortField")

I get the error on the second of these rows. The error is
"System.IndexOutOfRangeException: Cannot find column ServerName. at
System.Data.DataTable.ParseSortString(String sortString) at
System.Data.Select..ctor(DataTable table, String filterExpression,
String sort, DataViewRowState recordStates) at
System.Data.DataTable.Select(String filterExpression, String sort) at
Project.WebForm3.Sub()"

Let me know if you find anything!
Kat
 
Back
Top