For some of my 3-tier application that use WCF, I use a multistep test to check why I cannot access the online data.
At first, we check if the computer is quarantined (saw this feature at the launch event of Windows 2008)
ManagementScope scope = new ManagementScope(@"\root\nap");
scope.Connect();
ObjectQuery query = new ObjectQuery("SELECT * FROM NAP_Client");
using (ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query))
{
int isolationState = 0;
foreach (ManagementObject m in searcher.Get())
{
isolationState = int.Parse(m["systemIsolationState"].ToString());
}
if (isolationState == 3) // 3 means in quarantine
{
//NAP is preventing the computer access to the network
....do something
}
}
Then we proceed with testing if we have access to the internet using this API:
[DllImport("wininet.dll")]
private extern static bool InternetGetConnectedState(out ConnectedStateFlag lpdwFlags, int dwReserved);
[Flags]
private enum ConnectedStateFlag : int
{
Configured = 0x40,
LAN = 0x02,
RasInstalled = 0x10,
Modem = 0x01,
ModemBusy = 0x08,
Offline = 0x20,
Proxy = 0x04
}
Then, I open a socket and try connecting to the server address.
Then I try creating an instance of a web service to see if IIS is running properly and is not causing any error.
Then I call a function on the web service that tells me if the database is online.