views:

46

answers:

2
MySqlCommand command = connection.CreateCommand();
command.CommandText = string.Format("SELECT * FROM characters WHERE account_id = '{0}'", this.ID);
MySqlDataReader reader = command.ExecuteReader();

while (reader.Read()) { ... }

I get an error at the last line saying "Invalid attempt to Read when reader is closed." Now, if I add another line before it, as in:

MySqlCommand command = connection.CreateCommand();
command.CommandText = string.Format("SELECT * FROM characters WHERE account_id = '{0}'", this.ID);
MySqlDataReader reader = command.ExecuteReader();
reader = command.ExecuteReader(); // Here.

while (reader.Read()) { ... }

I get an error at that new line saying "There is already an open DataReader associated with this Connection which must be closed first."

Alright, I don't want to get picky here, but is my reader open or closed?

A: 

It's a typo or you are trying to read from another reader, not the one you've opened?

MySqlDataReader reader = command.ExecuteReader();

and then:

filler.Reader.Read()
Sorry, missed that. Tried to make the explanation more generic, but it's the same reader. Edited in 1 second.
Lazlo
A: 

This may be from a bug in MySqlDataReader that has been documented here.

Also, after this line:

MySqlDataReader reader = command.ExecuteReader();

use a debugger to find the value of the following:

reader.IsClosed;

This will give better insight as to whether or not the reader is open or closed.

Doc Hoffiday