I am new to vb.net and I am interested in attempting to connect to an SQL Server. I am pretty certain the answer I seek is found in System.Threadin g.Timer
I want to keep trying to connect a number of times before giving up and throwing an error.
Below is my code from inside my SQLDatabase class.
Before Connect is called, I have ensured the Connection string is set to the variable _Connection, and, that it is not already open
_Connection is a SQLConnection object
Private Sub Connect(ByVal MaxTries As Integer, ByVal Interval As Integer)
Dim ThisTry As Integer = 1
While ThisTry <= MaxTries
Try
_Connection.Ope n()
ThisTry = 0
Exit Sub
Catch ex As Exception
If ThisTry = MaxTries Then
Throw New Exception(ex.Me ssage)
End If
Dim oCallback As New Threading.Timer Callback(Addres sOf OnTimedEvent)
Dim oTimer As New System.Threadin g.Timer(oCallba ck)
oTimer.Change(0 , Interval)
End Try
End While
End Sub
Private Sub OnTimedEvent(By Val WhoIsThis As Object)
End Sub
What else to I need to do to make this work? Any suggestions would be greatly appreciated.
Thanks,
Steve
I want to keep trying to connect a number of times before giving up and throwing an error.
Below is my code from inside my SQLDatabase class.
Before Connect is called, I have ensured the Connection string is set to the variable _Connection, and, that it is not already open
_Connection is a SQLConnection object
Private Sub Connect(ByVal MaxTries As Integer, ByVal Interval As Integer)
Dim ThisTry As Integer = 1
While ThisTry <= MaxTries
Try
_Connection.Ope n()
ThisTry = 0
Exit Sub
Catch ex As Exception
If ThisTry = MaxTries Then
Throw New Exception(ex.Me ssage)
End If
Dim oCallback As New Threading.Timer Callback(Addres sOf OnTimedEvent)
Dim oTimer As New System.Threadin g.Timer(oCallba ck)
oTimer.Change(0 , Interval)
End Try
End While
End Sub
Private Sub OnTimedEvent(By Val WhoIsThis As Object)
End Sub
What else to I need to do to make this work? Any suggestions would be greatly appreciated.
Thanks,
Steve