Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Connecting to SQL server behind firewall advice

Posted on 2013-06-01
3
Medium Priority
?
268 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
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…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

715 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