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

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

Cross-database transaction BUG #794

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


Copy link

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

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.");

    // MySql.Data support this test

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


        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

Copy link

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.

Copy link

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

No branches or pull requests

2 participants