Skip to content

Exception InvalidOperationException with dapper and transaction #452

@daikoz

Description

@daikoz

Hi,

I try to execute a insert with dapper in a transaction:

            using (MySql.Data.MySqlClient.MySqlConnection conn = new MySql.Data.MySqlClient.MySqlConnection("server=XXX;user id=Test;password=Test;database=Test"))
            {
                conn.Open();

                using (MySqlTransaction trans = conn.BeginTransaction())
                {
                    string test = "";
 
                    conn.Execute(@"INSERT INTO Test(@test)", new { test = test });
                    trans.Commit();
                }
            }

On execute, i have this exception:

System.InvalidOperationException
HResult=0x80131509
Message=The transaction associated with this command is not the connection's active transaction.
Source=System.Private.CoreLib
StackTrace:
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at MySql.Data.MySqlClient.MySqlCommand.ExecuteNonQuery() in C:\projects\mysqlconnector\src\MySqlConnector\MySql.Data.MySqlClient\MySqlCommand.cs:line 60
at Dapper.SqlMapper.ExecuteCommand(IDbConnection cnn, CommandDefinition& command, Action2 paramReader) in C:\projects\dapper\Dapper\SqlMapper.cs:line 2827 at Dapper.SqlMapper.ExecuteImpl(IDbConnection cnn, CommandDefinition& command) in C:\projects\dapper\Dapper\SqlMapper.cs:line 570 at Dapper.SqlMapper.Execute(IDbConnection cnn, String sql, Object param, IDbTransaction transaction, Nullable1 commandTimeout, Nullable`1 commandType) in C:\projects\dapper\Dapper\SqlMapper.cs:line 443

Follow the test project:
TestMysqlconnector.zip

I use:

  • Visual studio 15.6.2
  • MySqlConnector 0.36.1
  • Dapper 1.50.4
  • .NET Core v2.1.0-preview1-26216.03

This code work fine with mysql connector of Oracle.

Regards

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