Question

Currently, I'm working on a Windows Based System which uses mySQL as Database. The database can be on a Remote Computer connected to the same Network. My Problem is, how can I check if this Remote Address to be my Database source is existing or currently reachable.

Was it helpful?

Solution

bool CheckConnectionStatus()
{
    String strConnection="/*your connection string here*/";
    SqlConnection con = new SqlConnection(strConnection);
    if(con.State == ConnectionState.Closed)
    {
       try
      {        
       con.Open();
       con.Close();
      }
       catch(Exception e)
      {
        return false;
      }
    }
    else
   {
    return true;
   }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top