4

the problem i have manifests it self only on the latest version of MySQL Connector .Net (6.10 at this date)

For ages i have the following working correctly in Both MSSQL and MYSQL:

  1. Create DbConnection
  2. Create DbCommand using previous connection
  3. Execute
  4. Get DbDataReader
  5. Dispose of DbCommand, not the connection (Done at this point because its a wrapper class)
  6. Read the data from the DbDataReader

All of this is working correctly in MSSQL and MYSQL v6.9 (even SQLite since the wrapper class handles it to)

Now, with MySQL Connector 6.10, when the DbCommand gets Disposed, the DataReader gets closed.

My question is: Can anyone confirm that this behaviour is here to stay or may reverted in the future?

Its a bit odd having DB providers behaving differently from one another a such a high level.

I realize this may be better asked on MySQL Developer Zone, but i don't have an account, maybe i will need to create one.

Thank you

1

1 Answer 1

5

This is definitely a change in MySql.Data 6.10: https://github.com/mysql/mysql-connector-net/commit/ae13ac2dc3fd0da24c158b9a40a6e3362d27f05b

I added a test based on your steps (code is at the end of this answer) to AdoNet.Specification.Tests and ran it against a variety of providers.

The following connectors handled it just fine:

The following two failed:

I’d consider this a regression in MySql.Data 6.10.x; unfortunately the commit comment doesn't provide any clue as to why this behaviour was changed. Your best chance for getting it addressed is filing a bug report at https://bugs.mysql.com/. Alternatively, consider switching to MySqlConnector, an OSS replacement for MySql.Data that fixes a number of longstanding bugs, plus adds true async support.

Update: The bug report has been created: MySQL Bug #89159.

Update 2: This bug should be fixed in Connector/NET 8.0.20.

Sample test code to reproduce the failure:

[Fact]
public virtual void Dispose_command_before_reader()
{
    using (var connection = CreateOpenConnection())
    {
        DbDataReader reader;
        using (var command = connection.CreateCommand())
        {
            command.CommandText = "SELECT 'test';";
            reader = command.ExecuteReader();
        }

        Assert.True(reader.Read());
        Assert.Equal("test", reader.GetString(0));
        Assert.False(reader.Read());
    }
}
1
  • Thank you very much for the reply. For now i will have to keep 6.9. No time to refactor old working code because of this. Will take a look at MySqlConnector. Thanks
    – MaxSantos
    Dec 14, 2017 at 11:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.