Link to home
Start Free TrialLog in
Avatar of Murray Brown
Murray BrownFlag for United Kingdom of Great Britain and Northern Ireland

asked on

VB Fastest way to seeif a SQL database can be connected to

Hi

I am using the following code to test a connection to a SQL database. If the connection cannot be made it takes about 30 seconds. Is there a faster way to do this?

        Try
            'TEST SQL CONNECTION
            If My.Settings.DBType = "SQL" Then

                Dim xSQL As String
                Dim connection As New SqlConnection(My.Settings.CS_Setting)
                Dim cmd As New SqlCommand(xSQL, connection)
                connection.Open()
                'This takes about 30 seconds
                connection.Close()
            End If

        Catch ex As Exception
            MsgBox("NO SQL Connection. The Magic Box will be deactivated")

        End Try
SOLUTION
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Murray Brown

ASKER

Thanks very much for the advice