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
{{ message }}
Repository navigation
Explicit Database.BeginTransaction vs ambient transaction. #1110
It should be mentioned that explicitly starting a database transaction via call DbContext.Database.BeginTransaction() will lead to exception if it is done inside ambient transaction scope.
The thrown exception is:
System.InvalidOperationException: 'An ambient transaction has been detected. The ambient transaction needs to be completed before beginning a transaction on this connection.'
@voroninp this restriction doesn't really have anything to do with EF Core - you're effectively asking to start two transactions on the same connection, and that's not supported at the low-level driver layer. As always, there's a documentation balance to be struck, where detailing each and every possible not-supported pattern is detrimental in general. And in any case, any user attempting to do this would immediately get an informative exception telling them that this isn't supported, so I'm not sure what value a doc not would have here.
@limup you must either use TransactionScope or BeginTransaction, but not both.
@voroninp this restriction doesn't really have anything to do with EF Core - you're effectively asking to start two transactions on the same connection, and that's not supported at the low-level driver layer. As always, there's a documentation balance to be struck, where detailing each and every possible not-supported pattern is detrimental in general. And in any case, any user attempting to do this would immediately get an informative exception telling them that this isn't supported, so I'm not sure what value a doc not would have here.
@limup you must either use TransactionScope or BeginTransaction, but not both.
Activity
limup commentedon Oct 10, 2022
I've got the same error. Any idea how the fix them?
roji commentedon Oct 10, 2022
@voroninp this restriction doesn't really have anything to do with EF Core - you're effectively asking to start two transactions on the same connection, and that's not supported at the low-level driver layer. As always, there's a documentation balance to be struck, where detailing each and every possible not-supported pattern is detrimental in general. And in any case, any user attempting to do this would immediately get an informative exception telling them that this isn't supported, so I'm not sure what value a doc not would have here.
@limup you must either use TransactionScope or BeginTransaction, but not both.
limup commentedon Oct 11, 2022
Ok, I understood now. Thank you for answer.