Solved

Connecting to SQL server behind firewall advice

Posted on 2013-06-01
3
261 Views
Last Modified: 2013-06-01
I have an app that I have written that uses a SQL server that is behind a firewall. Each user has to launch iexpolorer then click a web link that lists all our firewalls before launching my app.

The problem is that it takes 60 seconds or more for either the firewall or SQL server to timeout in my app (not sure which). After which I pop a messagebox with a link to the webpage with the firewall links. Users are impatient because my app gives the appearance that nothing is going on.

I need some way to check the firewall state as soon as my app opens.

I thought what about internet history, I could check that when my app opens. I found some code that gets the history which I search for the firewall link.

But is there a way to check if the user connected to the firewall today? is there a date associated with the history.

MW
0
Comment
Question by:WINN2012
  • 2
3 Comments
 
LVL 25

Expert Comment

by:clockwatcher
ID: 39213341
I would suggest having your client try to ping your server before you connect:

    Sub Main()
        If My.Computer.Network.Ping("YOUR_SQLSERVER") Then
            ' Continue with your program
        Else
            MessageBox.Show('Please connect to the firewall first')
        End If

    End Sub

Open in new window

0
 

Author Comment

by:WINN2012
ID: 39213389
I had tried that, its strange that I can ping the server without connecting to the firewall. I can get to the DB until I connect the firewall.

MW
0
 
LVL 25

Accepted Solution

by:
clockwatcher earned 500 total points
ID: 39213489
If you're using TCP/IP as your client protocol rather than something like named pipes, you can "ping the port" that sql server is running on.  Basically, try to set up a connection (with a timeout) on the port that your sql server is listening on,  if you can connect before the timeout  then you should be good to go.  If you can't then direct them to your firewall page.

    Sub Main()
        Dim client as new TcpClient()
        Dim result as IAsyncResult

        Dim server as String = "YOUR_SQLSERVER"
        Dim port as Integer = 1433 'default port that sql server listens on
        Dim timeout as Integer = 3000 'timeout in milliseconds
        Dim connected as Boolean = False

        result = client.BeginConnect(server, port, Nothing, Nothing)
        Dim wh as System.Threading.WaitHandle = result.AsyncWaitHandle
        if wh.WaitOne(timeout, False) then
            if client.Connected then
                connected = True
                client.close()
                ' continue your program
            end if
        end if
        client.close()
        if not connected then 
            MessageBox.Show("Connect to the firewall")
        end if 

    End Sub

Open in new window

0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now