I am using EF Core 3.1 to connect to SQL Server. I would like to SET XACT_ABORT ON
for SQL Server on for all the connections I make in my application.
Is there a hook on start up or context creation that I can run this? Because I am working with AWS RDS, I do not have the ability to turn it on server wide.
Any help would be appreciated.
Open the SqlConnection and set XACT_ABORT ON before passing the open SqlConnection to your DbContext constructor. The pattern for BYO-connection in EF core is
or if you're using DI, introduce a IDbConnectionFactory or somesuch and write
Passing an open connection to the DbContext constructor will prevent the DbContext from opening and closing the connection for each command. This might slightly increase the size of your connection pool, but it shouldn't be a big deal.