I developed a winform application using VB.NET. The application is deployed in a machine that is connected to a wireless network. The car is in a car (moving object).
The application has DataGridViewdownloaded data from MSSQL Server (on a remote computer). Data is updated every 5 seconds.
I used the event NetworkAvailabilityChangedto determine the status of the network. If the network is available, I retrieve the data from the table.
The code:
AddHandler NetworkChange.NetworkAvailabilityChanged, AddressOf NetworkStateChangeHandler
Public Sub NetworkStateChangeHandler(ByVal sender As Object,
ByVal e As NetworkAvailabilityEventArgs)
If e.IsAvailable = True Then
g_bNetworkAlive = True
Else
g_bNetworkAlive = False
End If
End Sub
private Sub GetData()
If g_bNetworkAlive = True
'code to get the data from table
End If
End Sub
Question:
If the car movers out of the out of the network, the event NetworkAvailabilityChangeddoes not start. therefore, it throws the following error every 5 seconds, and the application crashes.
A network-related or instance-specific error occurred while establishing
a connection to SQL Server. The server was not found or was not accessible.
: Ping SQL Server 5 , . .
. Wi-Fi, NetworkAvailabilityChanged event is fired. , .
- ?