Re: Urgent...Please Help...
From: W.G. Ryan eMVP (WilliamRyan_at_gmail.com)
Date: 10/29/04
- Next message: Antonio: "Thumb of web pages"
- Previous message: Stephen: "Re: Writing arraylist items to the page"
- In reply to: Irfan Akram: "Urgent...Please Help..."
- Next in thread: Irfan Akram: "Re: Urgent...Please Help..."
- Reply: Irfan Akram: "Re: Urgent...Please Help..."
- Messages sorted by: [ date ] [ thread ]
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
>
>
>
- Next message: Antonio: "Thumb of web pages"
- Previous message: Stephen: "Re: Writing arraylist items to the page"
- In reply to: Irfan Akram: "Urgent...Please Help..."
- Next in thread: Irfan Akram: "Re: Urgent...Please Help..."
- Reply: Irfan Akram: "Re: Urgent...Please Help..."
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|