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


Yes Was this page helpful? No
Yes Was this page helpful? No