DataReader Close causes system to hang.

LeifW

New member
Joined
Aug 2, 2005
Messages
1
Hi,

I have a problem which I hope is easy. I have a program written in C#. Im using a DataReader to retrive 4 rows of data from a Sybase database. Everything seems to work fine except when I call the DataReader.Close() method. The system just hangs. Im using the OleDbDataReader. When I trace through the code using the debugger, I see that correct data is being returned in a timely manner. Also if I use Odbc objects (OdbcConnection, OdbcDataReader, OdbcCommand) with the appropriate connect string, everything works fine. Any help or guidance would be appreciated. Thanks. Heres the code.

OleDbConnection myConn = new OleDbConnection(Session["ConnectionString"].ToString());
string mySelectQuery = "select id from Cashflow where number = 464000";
OleDbCommand myCommand = new OleDbCommand(mySelectQuery,myConn);
OleDbDataReader dr;
myConn.Open();
dr = myCommand.ExecuteReader();
while (dr.Read())
{
ListBox2.Items.Add(dr[0].ToString());
}

dr.Close(); // <---- System hangs here!
myConn.Close();


Thanks,
LeifW
 
Try calling cancel on the underlying command object within the reader - cant remember the syntax offhand but the underlying command object has work to do once the reader is finished - if you call the command objects cancel method before closing the reader it may help.
 
Back
Top