Verify connection to database in Entity Framework Core
Asked 2 years 10 months 3 days 7 hours 32 minutes  ago, Viewed 2199 times
                You need to run a query against the database and then examine the results. We don't care about the return value because the query will throw an exception if the execution fails.
VisitorsController.cspublic bool CheckConnection()
{
   bool con = false;
   try
   {
      var books = context.Visitors.FromSqlRaw("SELECT * FROM Visitors LIMIT 1").ToList();
      con = true;
   }
   catch (Exception e)
   {
      con = false;
   }
   return con;
}
                    Like 
          
        
                    8