Slow to close MySqlDataReader

Slow to close MySqlDataReader

Postby hrjun » Mon 15 May 2006 02:49

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.
hrjun
 

Postby Alexey » Mon 15 May 2006 08:59

This happens because MySql database retrieves all the records from the table. We can't change MySql database server.
Alexey
 
Posts: 2756
Joined: Mon 13 Mar 2006 07:43

Postby Alexey » Tue 16 May 2006 14:44

Try to use ExecutePageReader method.
Alexey
 
Posts: 2756
Joined: Mon 13 Mar 2006 07:43


Return to dotConnect for MySQL