'C# What to do if connection fails with Entity Framework
I'm sorry for the rudimentary question.
I created a program to connect to PostgreSQL(NpgSQL) using Entity Framework 6 in a C# console app.
If the connection to the database fails, what should I do if I want to try to reconnect?
static void GetStartProcessTime()
{
try
{
using (var context = new DbContext())
{
var processingTimeTable = context.CheckprocessingTimeTable.First(x => x.id== 1);
processingTimeTable.CreateDate = DateTime.Now;
context.SaveChanges();
}
}
catch(Exception ex)
{
// How to write a reconnection?
}
}
I searched for an example like this, but I couldn't find it, and I don't know how to use it.
If it is a function that can retry even if the connection fails like this, please tell me how to do it with PostgreSQL.
Sorry for the poor English and the rudimentary questions.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
