S
Shawn Berg
Upon executing a stored procedure using the Data Access application block's
SQLHelper class, I would like to continually retry to execute it every 1
second up to 3 times if an exception occurs. For example, if for some reason
the database server is down, a timeout occurs, etc. I would like to
automatically retry a certain number of times before giving up. What is the
best way to accomplish this? Below is what I envision (pseudo-code):
Dim Retries As Integer = 0
Dim
Try
'// execute database command here
SQLHelper.ExecuteNonQuery(...)
Catch ex AS SQLException
If Retries <= 3 Then
Sleep(1000)
SQLHelper.ExecuteNonQuery(...)
End If
End Try
The problem I have with the code above is that I have duplicate code
(SQLHelper.ExecuteNonQuery(...)). The other problem I have, is what happens
when an exception occurs in the Catch block?
Any help would be greatly appreciated.
Thanks,
Shawn
SQLHelper class, I would like to continually retry to execute it every 1
second up to 3 times if an exception occurs. For example, if for some reason
the database server is down, a timeout occurs, etc. I would like to
automatically retry a certain number of times before giving up. What is the
best way to accomplish this? Below is what I envision (pseudo-code):
Dim Retries As Integer = 0
Dim
Try
'// execute database command here
SQLHelper.ExecuteNonQuery(...)
Catch ex AS SQLException
If Retries <= 3 Then
Sleep(1000)
SQLHelper.ExecuteNonQuery(...)
End If
End Try
The problem I have with the code above is that I have duplicate code
(SQLHelper.ExecuteNonQuery(...)). The other problem I have, is what happens
when an exception occurs in the Catch block?
Any help would be greatly appreciated.
Thanks,
Shawn