persistent sqlserver connection from vb.net for windows service

eliaslopezgtz

New member
Joined
Jul 11, 2003
Messages
1
Location
mexico
I am creating a windows service using .net framework 1.1 in vb.net this service monitors the serial port and writes both a log file and directly to the database...
and i want some sort of algorithm to make my database connection persistent no matter what happens this function has to handle all the timeouts, server busy, etc.. errors...
because i cant lose a bit of info from the serial port,
and i dont want to read again my log files... i just want to my service keeps trying until it can continue writing to the database

please help me.

Code:
Public Sub open_db_connection(ByVal mode As Integer)
        Dim t_boolean As Boolean
        t_boolean = False
        If mode <> 0 Then connDB.Close()
        Try
            If connDB.State <> ConnectionState.Open Then
                connDB.Close()
                connDB = New SqlClient.SqlConnection()
                connDB.ConnectionString = vCONNECTION_STRING
                connDB.Open()
            End If
            If connDB.State = ConnectionState.Open Then t_boolean = True Else t_boolean = False
        Catch e As Exception
            RaiseEvent t_error("Connection error : " & e.Message)
        End Try
        vOPEN_DB_CONNECTION = t_boolean
    End Sub
and in some point of my service when the connection is needed this code is in there...

Do
Loop Until vOPEN_DB_CONNECTION

but when I lost the connection my computer hangs because of the loop but then i reconnect my network cable and It doesnt return ...

I have another timer calling each second the function open_db_connection...

please help me...
 
Last edited by a moderator:
Back
Top