bbusdriver
bbusdriver

Reputation: 1627

Azure SetExecutionStrategy in ASP.NET Core 1.1

I am getting this error when I try to update several fields from the grid:

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

I could find a possible solution here, but not sure how I can turn the below suggested code (EF6+) into .Net Core version.

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

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

I get errors on DbConfiguration line and SetExecutionStrategy (need reference?)

If anyone knows how to convert this into .Net Core, I'd appreciate it if you can show me the steps or code snippets. Thanks!

Upvotes: 2

Views: 486

Answers (1)

coryseaman
coryseaman

Reputation: 387

In EF Core, you can use the following in the OnConfiguring method of your derived context, or in Startup.cs:

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
    optionsBuilder
        .UseSqlServer(
            @"Server=(localdb)\mssqllocaldb;Database=EFMiscellanous.ConnectionResiliency;Trusted_Connection=True;",
            options => options.EnableRetryOnFailure());
}

Upvotes: 2

Related Questions