Skip to content

MySql/MariaDB error "The transaction associated with this command is not the connection’s active transaction" occurs when a timeout error occurs #1467

@KaRom31

Description

@KaRom31

Hello,
I have a problem when using any method with MySql/MariaDb when a timeout error occurs.
When the operation timeout is exceeded, an error "The transaction associated with this command is not the connection’s active transaction" occurs, which hides the real problem. This problem is solved by the "IgnoreCommandTransaction=true" flag, but I would not like to always force this option to be used explicitly.

   at MySqlConnector.MySqlCommand.ExecuteNonQueryAsync(IOBehavior ioBehavior, CancellationToken cancellationToken) in /_/src/MySqlConnector/MySqlCommand.cs:line 309
   at MySqlConnector.MySqlCommand.ExecuteNonQuery() in /_/src/MySqlConnector/MySqlCommand.cs:line 108
   at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteNonQuery(RelationalCommandParameterObject parameterObject)
   at Microsoft.EntityFrameworkCore.RelationalDatabaseFacadeExtensions.ExecuteSqlRaw(DatabaseFacade databaseFacade, String sql, IEnumerable`1 parameters)
   at EFCore.BulkExtensions.SqlAdapters.MySql.MySqlAdapter.MergeAsync[T](DbContext context, Type type, IEnumerable`1 entities, TableInfo tableInfo, OperationType operationType, Action`1 progress, Boolean isAsync, CancellationToken cancellationToken)
   at EFCore.BulkExtensions.SqlAdapters.MySql.MySqlAdapter.Merge[T](DbContext context, Type type, IEnumerable`1 entities, TableInfo tableInfo, OperationType operationType, Action`1 progress)
   at EFCore.BulkExtensions.DbContextBulkTransaction.Execute[T](DbContext context, Type type, IEnumerable`1 entities, OperationType operationType, BulkConfig bulkConfig, Action`1 progress)
   at EFCore.BulkExtensions.DbContextBulkExtensions.BulkDelete[T](DbContext context, IEnumerable`1 entities, BulkConfig bulkConfig, Action`1 progress, Type type)

Code example:

using var db = new MainContext();
{
        try
        {
            var entitiesToDelete = db.Elements
                    .AsNoTracking()
                    .ToList();

            db.BulkDelete(entitiesToDelete);
        }
        catch (Exception ex)
        {

        }
}

Stack Trace:

at System.Threading.Tasks.ValueTask`1.get_Result()
   at MySqlConnector.MySqlCommand.<ExecuteNonQueryAsync>d__78.MoveNext()
   at System.Threading.Tasks.ValueTask`1.get_Result()
   at MySqlConnector.MySqlCommand.ExecuteNonQuery()
   at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteNonQuery(RelationalCommandParameterObject parameterObject)
   at Microsoft.EntityFrameworkCore.RelationalDatabaseFacadeExtensions.ExecuteSqlRaw(DatabaseFacade databaseFacade, String sql, IEnumerable`1 parameters)
   at Microsoft.EntityFrameworkCore.RelationalDatabaseFacadeExtensions.ExecuteSqlRaw(DatabaseFacade databaseFacade, String sql, Object[] parameters)
   at EFCore.BulkExtensions.SqlAdapters.MySql.MySqlAdapter.<MergeAsync>d__7`1.MoveNext()
   at EFCore.BulkExtensions.SqlAdapters.MySql.MySqlAdapter.Merge[T](DbContext context, Type type, IEnumerable`1 entities, TableInfo tableInfo, OperationType operationType, Action`1 progress)
   at EFCore.BulkExtensions.SqlBulkOperation.Merge[T](DbContext context, Type type, IEnumerable`1 entities, TableInfo tableInfo, OperationType operationType, Action`1 progress)
   at EFCore.BulkExtensions.DbContextBulkTransaction.Execute[T](DbContext context, Type type, IEnumerable`1 entities, OperationType operationType, BulkConfig bulkConfig, Action`1 progress)
   at EFCore.BulkExtensions.DbContextBulkExtensions.BulkDelete[T](DbContext context, IEnumerable`1 entities, BulkConfig bulkConfig, Action`1 progress, Type type)

EFCore.BulkExtensions: 8.0.3
Microsoft.EntityFrameworkCore: 8.0.4
Pomelo.EntityFrameworkCore.MySql: 8.0.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions