Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Entity Framework Core have connection resiliency configured by default?

I am reading through the documentation on connection resiliency in Entity Framework Core and learned that connection resiliency can be configured in ASP.NET Core while configuring the service:

public void ConfigureServices(IServiceCollection services)
{
    services.AddDbContext<PicnicContext>(
        options => options.UseSqlServer(
            "<connection string>",
            providerOptions => providerOptions.EnableRetryOnFailure()));
}

I noticed for other services, such as the Azure Search client, retry mechanisms are enabled by default. Is this the case for Entity Framework Core (3.1.3) as well, or do I need to explicitly call providerOptions => providerOptions.EnableRetryOnFailure()?

The SqlServerDbContextOptionsBuilder documentation does not provide much details on what the defaults are.

like image 697
Steven Jeuris Avatar asked Oct 15 '25 04:10

Steven Jeuris


1 Answers

The retry-on-failure functionality is implemented through the SqlServerRetryingExecutionStrategy. Calling EnableRetryOnFailure will basically configure this strategy as the execution strategy.

By default, Entity Framework Core will not use an execution strategy. Or rather, the default execution strategy is NoopExecutionStrategy (to be renamed to NonRetryingExecutionStrategy in EF Core 5) which doesn’t do anything.

So no, there is no default retry. And it’s usually a deliberate choice not to make automated retries. By default, a query will just fail and the error will bubble up so that developers can deal with it. If an application is written for retries in mind, then they can enable the functionality with a configuration that fits best.

like image 116
poke Avatar answered Oct 17 '25 19:10

poke



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!