List:MySQL and .NET« Previous MessageNext Message »
From:Jesse Date:August 8 2008 1:53pm
Subject:There is already an open DataReader associated with this Connection which must be closed first
View as plain text  
On one of my pages, when I hit the line of code where I close the Data 
Reader, I get the error, "There is already an open DataReader associated 
with this Connection which must be closed first.", but I'm SURE I've closed 
all of my previous Readers.  I've even tried using a secondary connection, 
and that doesn't work either.  The code is very simple:

         Cmd = New MySQLCommand(SQL,Conn)
         RS=Cmd.ExecuteReader()
         if RS.Read then
            cPID = RS("PayID").ToString
         end if
         RS.Close // Error occurs here.
         RS=Nothing
         Cmd=Nothing

"SQL" is a variable that holds my SQL statement. Basically, I'm executing a 
MySQL Function that will add a payment, and it returns the ID for the 
payment

I receive these messages every once in a while, and they ALWAYS happen on 
the line that says "RS=Cmd.ExecuteReader()". That's what I would expect, and 
100% of the time, it's because I forgot to close a reader somewhere. 
However, this one is happening when I'm trying to CLOSE the Data Set, and 
I'm sure I've closed all previous readers.  Does anyone have any ideas why 
this is happening?

Thanks,
Jesse 

Thread
There is already an open DataReader associated with this Connection which must be closed firstJesse8 Aug
  • Re: There is already an open DataReader associated with this Connection which must be closed firstJesse8 Aug
    • RE: There is already an open DataReader associated with this Connection which must be closed firstAndrew Armstrong10 Aug