Check Network and SQL server connections.
// Check network
private bool isNetworkConnectionAvailable()
{
bool _success = false;
string[] sitesList = { "www.google.com", "www.yahoo.com", "www.youtube.com" };
Ping ping = new Ping();
PingReply reply;
label1.Text = "";
int notReturned = 0;
try
{
for (int i = 0; i < sitesList.Length; i++)
{
reply = ping.Send(sitesList[i], 10);
if (reply.Status == IPStatus.Success)
{
_success = true;
Console.WriteLine("Ping " + sitesList[i] + " OK !");
break;
}
else
{
Console.WriteLine("Failed to ping " + sitesList[i] );
notReturned += 1;
}
}
}
catch
{
_success = false;
//throw new Exception(ex.Message);
}
return _success;
}Last updated
Was this helpful?