Link to home
Create AccountLog in
Avatar of Murray Brown
Murray BrownFlag for United Kingdom of Great Britain and Northern Ireland

asked on

VB.net Set Connection Timeout time

Hi
I use the following code to test if a connection can be made to a SQL database.
As it takes too long when the connection cannot be made I need to set the Connection Timeout to a shorter length. How would i do this and what would be a reasonable length?
The connection string can differ from user to user so I want try and achieve this with only the variable and not the actual connection string

        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
ASKER CERTIFIED SOLUTION
Avatar of YZlat
YZlat
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of Murray Brown

ASKER

Thanks very much