Solved

Connecting to SQL server behind firewall advice

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.

863 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

25 Experts available now in Live!

Get 1:1 Help Now