Microsoft.EntityFrameworkCore.Database.Transaction[20205] An error occurred using a transaction.

Error when working with Entity Framework core: Microsoft.EntityFrameworkCore.Database.Transaction[20205] An error occurred using a transaction. System.Data.SqlClient.SqlException (0x80131904): The COMMIT TRANSACTION request has no corresponding BEGIN TRANSACTION. at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
Please Login to see the rest of the answer
Answer: If you are saving your changes using _context.SaveChangesAsynch() then you need to change to _context.SaveChanges(). The reason why the errorr happens is because the transaction is run on Asynchronously. When you do _context.SaveChanges() or chain the function like: _context.[YourDataModel].Add([YourObject]).Context.SaveChanges(); The transaction happens in one commit and the Database connection does not close and reopen to save the changes.
Write an Article
If you log in, you will be notified when someone leaves a comment.

Other users would like to know if this solution helped you.

Kasiaric said:

Thanks a lot. I was actually using SavechangesAsync() instead of SaveChanges().


© 2022 - ErnesTech - Privacy