Closed microappstech closed 3 months ago
This happens because the connection is opened and closed transparently for each operation. To prevent this call context.Database.OpenConnectionAsync()
and context.Database.CloseConnection()
or switch to regular transactions (context.Database.BeginTransactionAsync()
).
I understand that this exposes some implementation details, but currently it's the recommended way to get transactional behavior as TransactionScope
isn't very reliable in async code.
I'm encountering an error with TransactionScope in my ASP.NET Core application. The error message is:
Here's the relevant sample code:
Aditional Context :
Environment : .NET Version: .NET Core 8 Blazor IDE: Visual Studio 2022 Database provider: Microsoft.EntityFrameworkCore.SqlServer Target framework: 8 =>net8.0
EF Version 8.0.2 =>
Operating system: Windows 11