Andre Pena
Andre Pena

Reputation: 59336

My database may become unavailable for aprox. 1 second some times. How do I prevent Entity Framework connection errors?

We have a critical application running on ASP.NET MVC 3.

Because of our failover solution, when a machine crashes, the database may take some time to recover, let's say, 1 second.

Entity Framework creates a connection everytime it saves changes or materializes objects. This connection may fail.

I'd like to implement something with Entity Framework so that it will try to connect again after a given time when the database connection fails.

I want this solution to be implemented only once per ObjectContext instance, that is, I don't want to put a try/catch surrounding every ToList or First.

Any suggestion?

Upvotes: 3

Views: 79

Answers (2)

Bas
Bas

Reputation: 27105

Check out Transient Fault Handling by Microsoft, it's created to do exactly what you are asking.

Upvotes: 1

Ladislav Mrnka
Ladislav Mrnka

Reputation: 364279

You may try to create your own EF Provider Wrapper. This will allow you to alter logic for database connections and database commands. You will have to play little bit with EF to find where to exactly put the retry logic in the wrapper but it is IMHO the best centralized place to use without creating a whole new provider.

Upvotes: 1

Related Questions