Timeout error from SqlDataReader even when ConnectionTimeout = 0

D

Dave Morse

Hi everyone,
I intermittently get a timeout error raised from a loop in which I am
iterating through records with a SqlDataReader in order to build a
Hashtable. The command object has its CommandTimeout property set to 0, so
it should never 'time out', but every once in a while it will, and only in
this particular place in the code.

The code is similar to:

SqlDataReader reader = {function to get the datareader};
while (reader.Read())
{
hashTable.Add(reader.GetString(0), reader.GetString(1);
}
reader.Close();

The stack trace for the error is:
Timeout expired. The timeout period elapsed prior to completion of the
operation or the server is not responding.
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception,
TdsParserState state)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException
exception, TdsParserState state)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning()
at System.Data.SqlClient.TdsParser.ReadNetlib(Int32 bytesExpected)
at System.Data.SqlClient.TdsParser.ReadBuffer()
at System.Data.SqlClient.TdsParser.ReadByteArray(Byte[] buff, Int32
offset, Int32 len)
at System.Data.SqlClient.TdsParser.ReadString(Int32 length)
at System.Data.SqlClient.TdsParser.ReadSqlValue(_SqlMetaData md, Int32
length)
at System.Data.SqlClient.TdsParser.ProcessRow(_SqlMetaData[] columns,
Object[] buffer, Int32[] map, Boolean useSQLTypes)
at System.Data.SqlClient.SqlDataReader.PrepareSQLRecord(Int32 i)
at System.Data.SqlClient.SqlDataReader.GetSqlString(Int32 i)
at System.Data.SqlClient.SqlDataReader.GetString(Int32 i)
at MyObject.CallingFunction

Using reflector to look at the TdsParser.ReadNetlib function, it looks like
it will throw an error if it reads less bytes from the stream that it
expects, and the error it chooses to throw is a timeout exception. It cannot
be reproduced in a development environment, only on test machines, and
usually only on those that have limited memory, but there are no other
memory related problems, just this one.

If anyone has experienced this problem before or has any insight, it would
be greatly appreciated.

Thanks,
Dave
 
G

Guest

Make sure you also set Command Time out to a large enough value. You may have
Command Timing out even though Connection timeout is not reached.


---

Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************
 
D

Dave Morse

I'm sorry, the title of this should read 'CommandTimeout = 0'. The command
timeout is set to 0, as well as the ConnectionTimeout.

Cowboy (Gregory A. Beamer) - MVP said:
Make sure you also set Command Time out to a large enough value. You may
have
Command Timing out even though Connection timeout is not reached.


---

Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************

Dave Morse said:
Hi everyone,
I intermittently get a timeout error raised from a loop in which I am
iterating through records with a SqlDataReader in order to build a
Hashtable. The command object has its CommandTimeout property set to 0,
so
it should never 'time out', but every once in a while it will, and only
in
this particular place in the code.

The code is similar to:

SqlDataReader reader = {function to get the datareader};
while (reader.Read())
{
hashTable.Add(reader.GetString(0), reader.GetString(1);
}
reader.Close();

The stack trace for the error is:
Timeout expired. The timeout period elapsed prior to completion of the
operation or the server is not responding.
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception,
TdsParserState state)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException
exception, TdsParserState state)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning()
at System.Data.SqlClient.TdsParser.ReadNetlib(Int32 bytesExpected)
at System.Data.SqlClient.TdsParser.ReadBuffer()
at System.Data.SqlClient.TdsParser.ReadByteArray(Byte[] buff, Int32
offset, Int32 len)
at System.Data.SqlClient.TdsParser.ReadString(Int32 length)
at System.Data.SqlClient.TdsParser.ReadSqlValue(_SqlMetaData md, Int32
length)
at System.Data.SqlClient.TdsParser.ProcessRow(_SqlMetaData[] columns,
Object[] buffer, Int32[] map, Boolean useSQLTypes)
at System.Data.SqlClient.SqlDataReader.PrepareSQLRecord(Int32 i)
at System.Data.SqlClient.SqlDataReader.GetSqlString(Int32 i)
at System.Data.SqlClient.SqlDataReader.GetString(Int32 i)
at MyObject.CallingFunction

Using reflector to look at the TdsParser.ReadNetlib function, it looks
like
it will throw an error if it reads less bytes from the stream that it
expects, and the error it chooses to throw is a timeout exception. It
cannot
be reproduced in a development environment, only on test machines, and
usually only on those that have limited memory, but there are no other
memory related problems, just this one.

If anyone has experienced this problem before or has any insight, it
would
be greatly appreciated.

Thanks,
Dave
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top