Click here to Skip to main content
15,937,429 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
HI All,

I have LAN based application connected with remote SQL server, therefore i want to check is LAN network is available to execute event like insert data update or select from remote server or otherwise it will occur error without LAN connectivity

i have try with
it will working great but my application has lot of events to execute with remote server, so i need to apply above code to every single of them like

if(System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable() == true)

//execute command...................... there are thousand of them....

MessageBox.Show("NO LAN Available");

SO I want small class for doing this separately from my current forms and classes that can do following things
01. real time LAN connection check and popup massage box to user, if LAN not Available this massage box not remove until LAN live again and the program not working until LAN back to live. like form open using ShowDialog(this);

Help me on this!


[edit]SHOUTING removed - OriginalGriff[/edit]
Updated 29-Mar-13 22:29pm
OriginalGriff 30-Mar-13 4:29am    
DON'T SHOUT. Using all capitals is considered shouting on the internet, and rude (using all lower case is considered childish). Use proper capitalisation if you want to be taken seriously.
JMMS Karunarathne 30-Mar-13 9:54am    
guys! sorry i' did not know that, i'll remember it so on..

1 solution

If i understand you well, you want to execute many commands to MS SQL server database located in your network.

In my opinion you don't need to check if LAN is available, because, when you try to connect to your SQL server (placed in LAN), program will show you a message error, that server is not available.

Use SQLConnection class[^]. to create new connection to your sql database and catch errors using: Try..Catch ...Finally...End Try[^] block.
You can set up many of SQLConnection class properties[^], like: connectiontimeout[^]

How to create Connections to SQL Server Databases[^]?
Detect Internet Network Availability[^]
Network Connection Detection C#[^]
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900