layris3 / Daily-learning-experience-record

daily learning experience
0 stars 0 forks source link

EF-connection resiliency #16

Open layris3 opened 4 years ago

layris3 commented 4 years ago

it is common to occur trasient errors when we access the database which is in cloud. the best way to solved this issue is just to try the access again and again.

we could use the "connection resiliency",which is the new feature of EF6,perfectly solved the problem above.

layris3 commented 4 years ago

how to use connection resiliency?

1\ create a class in your assembly that derives from the DbConfiguration class 2\ set the configuration

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