Page 1 of 1

Slow to close MySqlDataReader

Posted: Mon 15 May 2006 02:49
by hrjun
Hi there!

I have codes below...

Code: Select all

void doFetch()
{
	MySqlConnection dbConn; // make the connection via direct mode.
	MySqlCommand dbCmd = new MySqlCommand("select * from my_tbl", dbConn);
	
	MySqlDataReader dbReader = dbCmd.ExecuteReader();
	
	try {
		int limit = 10;
		while(dbReader.Read()) { // If the dbReader has 10000 records.
			// do something...
			if (limit++ > 1000) // break here!
				break;
		}	
	} finally {
		if (dbReader != null)
			dbReader.Close(); // VERY SLOW!!!!
	}
}

When I tested those codes with CoreLab's Oracle Provider, the dbReader closed immediately.
But CoreLab.MySql.MySqlDataReader was not.
(I'm not sure but it seems to read all the records in Close() or Dispose().)

I tested it with the 'DataReader' in ~CoreLab/MySQLDirect.NET2/Samples
on Windows XP SP2, MySQL4.x and CoreLab.MySql3.30.10.0.

How can I solve this problem?

Thanks in ahead.

Posted: Mon 15 May 2006 08:59
by Alexey
This happens because MySql database retrieves all the records from the table. We can't change MySql database server.

Posted: Tue 16 May 2006 14:44
by Alexey
Try to use ExecutePageReader method.