Solved

Connecting to SQL server behind firewall advice

Posted on 2013-06-01
3
263 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

777 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