Skip to content

Cross-database transaction BUG #794

Closed

Description

@fish-li

MySqlConnector has a bug, if start a transcation, i can't change database.

the same code, MySql.Data is OK

[TestMethod]
public void Test_Cross_database_transaction()
{
    Assembly asm = typeof(MySql.Data.MySqlClient.MySqlConnection).Assembly;

    if( asm.Location.EndsWith("MySqlConnector.dll") ) {
        Console.WriteLine("MySqlConnector has a bug, can't support this test.");
        return;
    }

    // MySql.Data support this test

    using( DbContext dbContext = DbContext.Create("mysql") ) {

        dbContext.BeginTransaction();

        var args1 = new { p1 = "abc" };
        dbContext.CPQuery.Create("insert into Trans1 (StrValue) values ( @p1 )", args1).ExecuteNonQuery();


        dbContext.ChangeDatabase("TestTrans");  // switch to another database

        var args2 = new { p1 = 123 };
        dbContext.CPQuery.Create("insert into Trans2 (IntValue) values ( @p1 )", args2).ExecuteNonQuery();

        // if MySqlConnector  ExecuteNonQuery(), throw a error:
        // System.InvalidOperationException: The transaction associated with this command is not the connection's active transaction; see https://fl.vu/mysql-trans

        dbContext.Commit();
    }
}

Activity

  1. bgrainger commented on Apr 2, 2020

    @bgrainger
    Member

    The current implementation of ChangeDatabase "closes" the current database, including the active transaction:

    await CloseDatabaseAsync(ioBehavior, cancellationToken).ConfigureAwait(false);

    I'm not entirely sure why this is; it may be a bug.

  2. added 2 commits that reference this issue on Apr 2, 2020
    960b4d8
    7caf5eb
  3. bgrainger commented on Apr 4, 2020

    @bgrainger
    Member

    Fixed in 0.63.1. Thanks for reporting it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions