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

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

Open
KaRom31 opened this issue Apr 19, 2024 · 0 comments

Comments

@KaRom31
Copy link

KaRom31 commented Apr 19, 2024

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)
        {

        }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant