ExecuteReader() throws exceptions
Posted by: Phi
Date: January 17, 2007 04:27AM

Aloha,

I'm using the MySQL .NET connector 1.0.7.30072 to connect to my database.

I have no problems connecting and calling ExecuteNonQuery() and ExecuteScalar(). The problem is ExecuteReader(). It works most of the time, but once in a while it gives me one of the following exception messages:
"The connection is already open"
"Connection must be valid and open"
"There is already an open DataReader associated with this Connection which must be closed first."

Here is my code:
try
{
mySqlConnection.Open();

MySqlCommand command = new MySqlCommand(sql, mySqlConnection);
return command.ExecuteReader(CommandBehavior.CloseConnection);
}
catch (Exception exception)
{
// Various error logging

mySqlConnection.Close();

return null;
}
finally
{
}

The connection is created in the constructor of my data access class.

An example sql statement that sometimes fail:
"SELECT CommentId, AccountItemId, RecipientAccountId, SenderAccountId, SenderName, SenderEmail, CommentText, CommentDate FROM Comment ORDER BY CommentDate DESC LIMIT 0, 20"

Thanks,
Phi

Options: ReplyQuote


Subject
Written By
Posted
ExecuteReader() throws exceptions
January 17, 2007 04:27AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.