Quantcast
Channel: Xojo Programming Forum - Latest topics
Viewing all articles
Browse latest Browse all 3791

Automatic Retry on Error

$
0
0

I am currently working on a project that has to communicate intensively with databases in a very unstable network. The number of lost packets is very high and therefore errors such as timeouts, dataloss and the like often occur.

Since I have to live with the network as it is, I am trying to teach my project to deal with these errors better. Better should mean that the user may notice that something is not running smoothly, but the project is trying its best.

That is why I added the following method to my mySQLCommunityServer subclass:

Public Function Load(SQLQuerry As String, ParamArray Params() As Variant) As RowSet
  Var rs As RowSet
  Var RetryCounter As Integer = 0
  
  While RetryCounter < 3
    
    Try
      
      If Not Self.IsConnected Then Self.Connect
      
      If Params <> Nil Then
        
        rs = Self.SelectSQL(SQLQuerry, Params)
        
      Else
        
        rs = Self.SelectSQL(SQLQuerry)
        
      End If
      
      Exit While
      
    Catch err As DatabaseException
      
      Self.ReportError(err, "OTRS Database Connection (" + SQLQuerry + ")")
      RetryCounter = RetryCounter + 1
      
    End Try
    
    If DebugBuild And RetryCounter > 0 Then Break
    
  Wend
  
  Return rs
End Function

It seems to work quite well, but I would like to hear further opinions and am open to suggestions for improvement.

Thank you for constructive criticism. :slight_smile:

9 posts - 4 participants

Read full topic


Viewing all articles
Browse latest Browse all 3791

Trending Articles