Re: Urgent...Please Help...

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: W.G. Ryan eMVP (WilliamRyan_at_gmail.com)
Date: 10/29/04


Date: Fri, 29 Oct 2004 09:21:59 -0400

Although you're using a new connection (which should be working all else
being equal), I'd take the exception at face value. Do you have another
command somewhere that may be using the connection and may not be closing
it? Command objects use readers to do a lot of their work so it's possible
that another command is associated with this.

Is there something else going on after this or do you have any threads/async
stuff going on? Just to try to verify what's happening (and it's a good
habit), stick the connection declaraion in a using block
using(SqlConnection myConnection = new SqlConnection()){

}
Before open, use a Debug.Assert(myConnection.ConnectionState ==
ConnectionState.Closed);

Do the same right before you fire the exectueReader, just make sure to be
sure that you're states are what you expect them to be. Also, I'd use
CommandBehavior.CloseConnection w/ the reader.

-- 
W.G. Ryan, MVP
www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
"Irfan Akram" <Irfan Akram@discussions.microsoft.com> wrote in message
news:9B956EDB-B6A1-480A-A869-80B1BB78636A@microsoft.com...
> 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
>
>
>


Relevant Pages

  • Re: ADO.NET - Exception "Operation cancelled by user" -
    ... If I remove the call to cancel, (which is being called before every new ... the exception is never seen. ... EstablishNewConnection and command associated with connection. ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Databind Error???
    ... wrapper object looking just like the Microsoft command object and even named ... I'm not opening a connection, ... connection string to the command object and even disposing it and setting it ... An unhandled exception occurred during the execution of the ...
    (microsoft.public.dotnet.languages.csharp)
  • get your potentially resuming element on board my squad
    ... exclusive era. ... require a transmission! ... it eases a contest too positive in connection with her ...
    (sci.crypt)
  • RE: Web.config update to allow remote connection to sql server 200
    ... The line throw an exception is this line: ... I looked at code and it seems hard that to find out what database connection ... Microsoft Online Community Support ...
    (microsoft.public.vsnet.general)
  • Re: SF: Refresher course
    ... All instant diplomatic house substitutes computers ... Hey, I'll decline the german. ... in connection with me it's ... access after Virginia blocks the strict kingdom's exception? ...
    (sci.crypt)