Bug #21315 Bug of MySqlDataReader.Close()
Submitted: 27 Jul 2006 13:19 Modified: 26 Sep 2006 19:13
Reporter: nie leo Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / NET Severity:S5 (Performance)
Version:1.0.7 OS:Windows (Windows)
Assigned to: CPU Architecture:Any
Tags: MySqlDataReader Close

[27 Jul 2006 13:19] nie leo
Description:
When I query a large table using MySqlDataReader in .NET, I can't cancel My operation imediately. I noticed some lines in source code:if (currentResult != null) urrentResult.Consume(); I think it's the reason. Please check it. Thank you!

How to repeat:
Query a large tabel using Command.ExecuteReader(),
then cancel the operation by calling DataReader.Close(),
you'll find it's take a long time.

Suggested fix:
delete the line: if (currentResult != null) urrentResult.Consume();
[27 Jul 2006 13:24] nie leo
Version 1.0.7
[9 Aug 2006 15:14] Tonci Grgin
Hello and thanks for your problem report. The solution is not so simple as you suggest I'm affraid. 
Tested with 3.5M rows table and got delay of about 10sec which is acceptable by me. Anyway, verified as described by reporter with latest Connector/NET 1.0.7 SVN.
Code snippet:
            MySqlConnection conn = new MySqlConnection();
            conn.ConnectionString = "DataSource=hostname;Database=dbname;UserID=username;Password=;PORT=3307";
            conn.Open();

            MySqlCommand command = new MySqlCommand();
            command.CommandText = "SELECT * FROM mpcjenik";// LIMIT 1000000
            command.CommandType = CommandType.Text;
            command.Connection = (MySqlConnection)conn;

            MySqlDataReader dr = command.ExecuteReader();
            MessageBox.Show("Before READ");
            dr.Read();
            MessageBox.Show("After READ");
            dr.Close();

            MessageBox.Show("Ready");
            command.Dispose();
            conn.Close();
[26 Sep 2006 19:13] Reggie Burnett
This is expected behavior.  The only way to cancel a resultset 'midstream' is to close the connection and this is not possible because of possible pending transactions.