Entity framework resiliency and retry logic

azure-functions entity-framework entity-framework-6

Question

I get a lot of errors when adding data to my Azure SQL server like this:

An exception has been raised that is likely due to a transient failure. If you are connecting to a SQL Azure database consider using

I can see on following link you can implement an azure strategy:

https://docs.microsoft.com/en-us/ef/ef6/fundamentals/connection-resiliency/retry-logic

In the article it is illustrated that you can use a standard Azure strategy:

public class MyConfiguration : DbConfiguration
{
    public MyConfiguration()
    {
        SetExecutionStrategy("System.Data.SqlClient", () => new SqlAzureExecutionStrategy());
    }
}

However it isent described how you apply it to your DbContext. Anyone tried this and can share som experience? It is not the core version, and it is implemented in a function. Out of 9000 call around 1000 fails so it a lot of errors.

1
0
3/4/2019 6:27:17 AM

Accepted Answer

You can use the DbConfigurationType attribute on the context class, specifying that it is to use your MyConfiguration class:

[DbConfigurationType(typeof(MyConfiguration))]
public class DataContext : DbContext, IDataContext
{
    ...
}
2
3/4/2019 7:20:36 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow