Timeout not working in SQL Connection

Posted by carlos on Stack Overflow See other posts from Stack Overflow or by carlos
Published on 2010-06-10T03:13:09Z Indexed on 2010/06/10 3:22 UTC
Read the original article Hit count: 162

Filed under:

I have this simple code to test that a DB is ready:

Function testlocalcon() As Boolean
    Dim constr As String = _clconstr

    Try
        Using t As New SqlConnection()
            constr = constr & " ; Connect Timeout=1"

            If Not t.State = Data.ConnectionState.Open Then
                t.ConnectionString = constr

                t.Open()
                If t.State = Data.ConnectionState.Open Then
                    Return True
                Else
                    Return False
                End If
            Else
                Return True
            End If
        End Using
    Catch ex As Exception
        Return False
    End Try
End Function

I do not want to execute a query, just to check the connection, but no matter what the time out parameter is ignored. I search here (Stackoverflow) and internet and found nothing in how to fix this.

Any one else have this problem? Or, are there any other ideas on how to let the application know that the DB is ready?

© Stack Overflow or respective owner

Related posts about vb.net