开发者

Contradictory MySqlReader errors

MySqlCommand command = connection.CreateCommand();
command.CommandText = string.Format("SELECT * FROM characters WHERE account_id = '{0}'", this.ID);
MySqlDataRead开发者_开发知识库er 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?


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.


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()
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜