3

I am wondering what the best approach is to managing/ monitoring a connection to a server database using the Entity Framework.

I know that the EF DB context or Object context does the main bits for you. However, in our scenario a user may unplug a network cable to the client or stop the server on the server machine, etc.

DB Server <-> Network <-> Fat Client (EF)

Therefore, in the above scenario if the network goes down and the client attempts any operation that requires data access there will be an exception (The underlying provider failed on open).

What is the best approach for detecting a loss of connection to a DB so that the client application (where the DB context/ UoW, Rep etc resides) can fail gracefully?

One solution that I have seen is to open a manual connection to the server DB (DBConnection) and then poll the DB using a Timer in C# and writing to a heartbeat table. Then catching the exception when it occurs. This seems like a massive hack to me.

Any help would be appreciated... Thanks in advance.

timmit
  • 181
  • 1
  • 6

0 Answers0