URGENT: How Can I Detect if I have a Connection to an SQL Server.

I have this application (POS) where I need to work offline. Then When I detect that I have a Connection t othe SQL server. I need to send the Info Collected to the server.
1. How to detect this connection from POS Station that are on the same Site location (Regular LAN).
2. How to detect this connection from POS Station that are Outside the location so the detection has to be over the internet.
3. What is the best way to set this up, a timer or is there a better way
LVL 1
ofern01Asked:
Who is Participating?
 
sk33v3Connect With a Mentor Commented:
If you want to test to see if you have a connection to a server I suggest using Ping. This is a network command taht many people use to test internet connectivity. No please note that some firewalls block ping so ensure that what ever you are pinging is configured to respond back.
0
 
ofern01Author Commented:
BTW, the language is VBNET 2005
0
 
vadim63Commented:
The simplest way is Try ... Catch ex As Exception ... End Try block with timer.
0
Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

 
corpusleCommented:
check the connection state like

if Connection.state = ConnectionState.Open
       ''thn ur connection exists
else
       '' no connection.


try it out
0
 
ofern01Author Commented:
In other words, I have to try to open the connection and catch the error to test for a connection?
Is this the only way?

0
 
ofern01Author Commented:
Also, how do I cantrol the timeout and what will be the must appropiate one. This way may take some time to return to operations; and I need it to be Very quick.
I was looking for something like ping.
0
 
vadim63Commented:
Try to send the Info Collected to the server:
1. set the timer1.interval=...
2.    
    Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Try
                    send the Info Collected to the server
                   Label1.Text = "Last Update: " & Now
        Catch ex As Exception
                     'do nothing
        End Try
    End Sub
0
 
ofern01Author Commented:
Is there a ping class or something similar within VBNET or do I have to run the ping program in windows?
0
 
sk33v3Commented:
This is cirectly from the object Browser in Visual Studio

Microsoft.VisualBasic.Devices.Network.Ping(String) As Boolean

Public Function Ping(ByVal hostNameOrAddress As String) As Boolean
     Member of: Microsoft.VisualBasic.Devices.Network
Summary:
Pings the specified server.

Parameters:
hostNameOrAddress: String. The URL, computer name, or IP number of the server to ping. Required.

Return Values:
Boolean indicating whether or not the operation was successful.

0
 
sk33v3Commented:
Something to note on ping commands. Occasional a ping packet will fail even though the remote device is configured and you are connected. The reason is basically because the packet that contained the ping information got "lost". So I would suggest pinging a few times before giving up on the connection not existing. Also bad internet connection will Drop packets more frequently than say a fiber optic internet connection. When I worked for an ISP logn long ago, they considered 1% packet loss acceptable however when something was wrong with the line the packet loss would hit 10% or higher. So maybe calling the ping command in a loop until you get a success or you ahve attempted to ping 10 times would nto be a bad idea.
0
 
ofern01Author Commented:
That is exactly What I was looking for. Now, server will have to have a public IP or How Do I make the server visible on the internet?
0
 
sk33v3Commented:
Ok at some point the server has to have a visible IP. This can be accomplished in a few ways. The first and easiest would be to have the server hosted and have a static public IP address. The next solution is to have a router on a public IP address and setup the port forwarding on the ports you need. This way the server is only exposed to the internet on the ports it needs to expose. This adds a layer of protection that just setting your server up on a public IP address does not offer. And the most complex of a way is to setup a VPN. The remote server network still has to have a public IP but the actual server does not. With a VPN you basically are connecting to it like it is a local server on your network. Depending on your exact needs depends on what will best fit your needs.
0
 
ofern01Author Commented:
It looks like the VPN is the way for me to go now.
This VPN have to be connected at all times, or can I just connect when I need it?
Can you direct me to a sample or article about this?
0
 
sk33v3Commented:
The VPN can be connected at all times or not. Kind of depends on the solution you choose. Some solutions are hardware and some are software. The hardware solutions will bascially always be connected as long as there is a connection.

http://aplawrence.com/Basics/vpn.html

Above is a link to an article breifly discussing VPN's. If you are nto familiar with setting up a VPN I would suggest that you hire a company that is. Setting them up can be a little frustrating if you don't know the ins and outs of the VPN solution you are using. When my company installs VPNS we usually use Sonic Walls because that is what we are familiar with.
0
All Courses

From novice to tech pro — start learning today.