Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cross-database transaction BUG #794

Closed
fish-li opened this issue Apr 2, 2020 · 2 comments
Closed

Cross-database transaction BUG #794

fish-li opened this issue Apr 2, 2020 · 2 comments

Comments

@fish-li
Copy link

@fish-li fish-li commented Apr 2, 2020

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();
    }
}
@bgrainger
Copy link
Member

@bgrainger bgrainger commented Apr 2, 2020

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.

@bgrainger
Copy link
Member

@bgrainger bgrainger commented Apr 4, 2020

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
Labels
None yet
Development

No branches or pull requests

2 participants