Urgent..Please Help...

G

Guest

I keep getting this irritating exception on and on. Please Help.


There is already an open DataReader associated with this Connection which
must be closed first.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information about
the error and where it originated in the code.

Exception Details: System.InvalidOperationException: There is already an
open DataReader associated with this Connection which must be closed first.

Source Error:


Line 84: OdbcCommand myCommand = new
OdbcCommand(mySelectQuery,myConnection);
Line 85: myConnection.Open();
Line 86: OdbcDataReader myReader = myCommand.ExecuteReader();
Line 87: myReader.Close();
Line 88:

Here is that part of the source Code..

private void CheckUser()
{

string connectionString = "DRIVER={MySQL ODBC 3.51 Driver};" +
"SERVER=localhost;" +
"DATABASE=markingsystem;" +
"UID=akramm;" +
"PASSWORD=rootuser;";

string mySelectQuery = "SELECT * FROM account_details";
OdbcConnection myConnection = new OdbcConnection(connectionString);
OdbcCommand myCommand = new OdbcCommand(mySelectQuery,myConnection);
myConnection.Open();
OdbcDataReader myReader = myCommand.ExecuteReader();
myReader.Close();


}

Note please that I only have 1 datareader, so the exception doesnt make
sense to me..


Your kind comments will be very much appreciated...

Thanks,

Irfan
 
J

JAPHET

Make Sure that all opened connection are closed, may be you have used the
same connection without closing it.Close the connection before applying it
to the data reader.
Japhet.
 
G

Guest

Hi Japhet,

As I told you, I have no instance where I am using the connection anywhere
else. That is the only class I'm using at the moment.

Thanks,

Irfan
 
L

Lerp

Hiya,

Try breaking the creation of your reader and executing on it into 2 steps
and see.

Cheers, Lerp :)
 

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