-
Notifications
You must be signed in to change notification settings - Fork 332
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
Cannot use transaction after commit #333
Comments
This code succeeds with |
I'll make the code more explicit:
It feels like it would be masking a programming bug to silently permit the second command to request the use of an invalid transaction for its command. (One can imagine more complex scenarios where a committed transaction is being passed to different methods where this could cause a significant data integrity problem.) I'm going to close this as "by design". If it turns out that it's causing significant backwards compatibility problems, we could consider adding a connection string option to opt in to the old behaviour. |
@bgrainger I encountered a similar problem, I created a transaction and did some changes to db, and meanwhile stored the transaction to a object, after I commit the transaction, I cannot use current db context again, the db context was set to use that disposed transaction. However, the same code works fine with sqlserver db connection, below is detail exception: System.InvalidOperationException: The transaction associated with this command is not the connection's active transaction.
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at MySql.Data.MySqlClient.MySqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
at Microsoft.EntityFrameworkCore.Storage.Internal.MySqlRelationalCommand.<ExecuteAsync>d__3.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.EntityFrameworkCore.Storage.Internal.MySqlRelationalCommand.Execute(IRelationalConnection connection, DbCommandMethod executeMethod, IReadOnlyDictionary`2 parameterValues)
at Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand.ExecuteReader(IRelationalConnection connection, IReadOnlyDictionary`2 parameterValues)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.Enumerator.BufferlessMoveNext(Boolean buffer)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.Enumerator.MoveNext()
at System.Linq.Enumerable.Single[TSource](IEnumerable`1 source)
at lambda_method(Closure , QueryContext )
at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.<>c__DisplayClass17_0`1.<CompileQueryCore>b__0(QueryContext qc)
at System.Linq.Queryable.Single[TSource](IQueryable`1 source, Expression`1 predicate)
at Gongfuge.BuildingBlocks.IntegrationEventLogEF.Services.IntegrationEventLogService.MarkEventAsPublishedAsync(IntegrationEvent event) in xxx\Services\IntegrationEventLogService.cs:line 45
at xxx.IntegrationEvents.OrderingIntegrationEventService.<PublishThroughEventBusAsync>d__5.MoveNext() in xxx\IntegrationEvents\OrderingIntegrationEventService.cs:line 37
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Gongfuge.Services.Ordering.API.Controllers.OrderingController.<SaveStatus>d__21.MoveNext() in xxx\Controllers\OrderingController.cs:line 551
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeActionMethodAsync>d__12.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeNextActionFilterAsync>d__10.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext context)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeInnerFilterAsync>d__14.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.<InvokeNextExceptionFilterAsync>d__23.MoveNext()
Thanks for your help :D |
Can you post (or link to) example code that shows this? |
@bgrainger Sure, there is a official sample project in sqlserver connection on github, this is a whole project and I have to explain in detail for UpdateProduct method, in UpdateProduct method:
|
Do you know if there's a fork of eShopOnContainers that has been changed to use MySQL and (I assume) Pomelo.EF? (There are so many forks it's not possible to browse them on GitHub.) |
Connector/NET allows the following code:
MySqlConnector throws an
InvalidOperationException: The transaction associated with this command is not the connection's active transaction.
on the last line.See #331 for a similar incompatibility.
The text was updated successfully, but these errors were encountered: