Domanda

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.

È stato utile?

Soluzione

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;
   }
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top