You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
MySqlConnector has a bug, if start a transcation, i can't change database.
the same code, MySql.Data is OK
[TestMethod]publicvoidTest_Cross_database_transaction(){Assemblyasm=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 testusing(DbContextdbContext=DbContext.Create("mysql")){dbContext.BeginTransaction();varargs1=new{p1="abc"};dbContext.CPQuery.Create("insert into Trans1 (StrValue) values ( @p1 )",args1).ExecuteNonQuery();dbContext.ChangeDatabase("TestTrans");// switch to another databasevarargs2=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-transdbContext.Commit();}}
Activity
bgrainger commentedon Apr 2, 2020
The current implementation of
ChangeDatabase"closes" the current database, including the active transaction:MySqlConnector/src/MySqlConnector/MySql.Data.MySqlClient/MySqlConnection.cs
Line 249 in 578c993
I'm not entirely sure why this is; it may be a bug.
Don't close active transaction in ChangeDatabase. Fixes #794
Don't close active transaction in ChangeDatabase. Fixes #794
bgrainger commentedon Apr 4, 2020
Fixed in 0.63.1. Thanks for reporting it!