Question: I have this error come up in Asp.Net 5 Production environment hosted in IIS, how should I solve this error?
The error states "The configured execution strategy 'SlqServerRetryingExecutionStrategy' does not support user-initiated transactions. Use the execution strategy returned by DbContext.Database.CreateExecutionStrategy()' to execute all the operations in the transaction as a retriable unit".
Login to See the Rest of the Answer
Answer: Basically, this error is telling you that you have configured your Database Context Services to retry connecting to the Database Server in case the connection is lost. However, there is a connection disconnect in the middle of saving the Context/Objects to the Database, this creates that error as the "Execution Strategy" can not be used to resubmit the unsuccessful committed objects to the database.
In order to solve this error, follow the steps below:
1. Re-evaluate whether it is important for you to use add
the SqlServerOptionsAction that lets the connection be retried on failure
- If not then do not retry on failure
2. If you are using an Async Function to insert into the database, make sure that you are "await" awaiting all operations IO or Database Bound. This will help you
narrow down where the error might be coming from.
3. Do not mix None-Async function calls with Async Function calls, this will create a lot of problems as different operations/tasks might be executing on different threads than others. Separate Async and None Async functions call into respective Async and None Async Functions.
4. According to the doc, you could manually invoke the execution strategy by using delegates. Visit the link to read more about the solution.
5. Do nothing, the error is less likely to occur and if it happens then the application will throw an exception you can then handle the exception with the right instruction.
6. Find out if the Network Infrastructure the Application is hosted on has issues regarding Network disconnect.
7. Check the Web Server (IIS) to see if the Application Pool is recycling the task/connection every couple of minutes. If so, then increase the time the Application Pool recycles.
Leave a comment below if this helped you, if not let us know in the comments below as well.