I think I must be going crazy?!
I am using a DataReader (OleDb in this case) to select some records from a
table. When I let the code execute it runs fine (via an ASP.Net page).
When I step through it using the debugger - the DataReader acts very
strange... My table has 5 records and while debugging it will iterate 2 out
of the 5 records before the call to Read() returns false.

This has been driving me nuts for a few hours now - hoping I am just really
beat and doing something obvious. Any insights, etc would be greatly
appreciated.
Below is a simplified block of code that reproduces the issue on my machine.

OleDbConnection oConn = new OleDbConnection(
System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"] )
;
oConn.Open();
OleDbCommand oCmd = new OleDbCommand("SELECT * FROM tblClients Order By
ClientID", oConn);
OleDbDataReader oReader = oCmd.ExecuteReader();
string a = "";

//--this block executes correctly unless I decide to step through it
//--the results read "1,2,3,45," when I just let it go
//--when I step through it I get "2,5,"
while( oReader.Read() )
{
a = oReader.GetValue(0).ToString();
Response.Write( a + "," );
}

oReader.Close();
oConn.Close();

Thanks,
G. Herrell

Re: DataReader Troubles by Scott

Scott
Thu Dec 18 18:58:34 CST 2003

I recently went through this myself and found that stepping through the code
(and adding watches and such) cause the DataReader to invoke its Read method
prematurely. In other words, the debugging is actually causing the problem.


"Greg Herrell" <gherrell@indy.rr.com> wrote in message
news:TDqEb.7488$031.5634@fe3.columbus.rr.com...
> I think I must be going crazy?!
> I am using a DataReader (OleDb in this case) to select some records from a
> table. When I let the code execute it runs fine (via an ASP.Net page).
> When I step through it using the debugger - the DataReader acts very
> strange... My table has 5 records and while debugging it will iterate 2
out
> of the 5 records before the call to Read() returns false.
>
> This has been driving me nuts for a few hours now - hoping I am just
really
> beat and doing something obvious. Any insights, etc would be greatly
> appreciated.
> Below is a simplified block of code that reproduces the issue on my
machine.
>
> OleDbConnection oConn = new OleDbConnection(
>
System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"] )
> ;
> oConn.Open();
> OleDbCommand oCmd = new OleDbCommand("SELECT * FROM tblClients Order By
> ClientID", oConn);
> OleDbDataReader oReader = oCmd.ExecuteReader();
> string a = "";
>
> //--this block executes correctly unless I decide to step through it
> //--the results read "1,2,3,45," when I just let it go
> //--when I step through it I get "2,5,"
> while( oReader.Read() )
> {
> a = oReader.GetValue(0).ToString();
> Response.Write( a + "," );
> }
>
> oReader.Close();
> oConn.Close();
>
> Thanks,
> G. Herrell
>
>