Is there way to check if the server is live or active besides writing a sql query insert, delete, or add query and you get the -40 error when the server is not available
.
Is there a command or some type of sql query to verify if the server is active?
Loading
David SmithPosted Jul 7, 2011, 10:23 AM
So the value is returning a bool
Amit ChoudharyPosted Jul 7, 2011, 5:18 AM
=> Use osql or sqlcmd to try " osql /S
[Full article here]
From your c# code:
using System;
using System.Net.NetworkInformation;
namespace ASPDeveloperNet_BitShopPingSample
{
class Program
{
static void Main()
{
BitShopPing("www.ASPDeveloper.Net");
}
public static int BitShopPing(string hostname)
{
Ping ping = new Ping();
PingReply reply = ping.Send(hostname);
if (reply.Status == IPStatus.Success)
{
// TODO: Remove debugging output. Sample is a console app.
Console.WriteLine("Address: {0}", reply.Address.ToString());
Console.WriteLine("RoundTrip time: {0}", reply.RoundtripTime);
Console.WriteLine("Time to live: {0}", reply.Options.Ttl);
Console.WriteLine("Don't fragment: {0}", reply.Options.DontFragment);
Console.WriteLine("Buffer size: {0}", reply.Buffer.Length);
return (1);
}
else
{
return (0);
}
}
}
}
Thanks.
Please mark the answer if it helped you.