0

I am implementing a recovery feature for an application with multiple methods making data access calls to SQL Server. The idea is to be able to the subscriber database if the connection failed.

I would like to centralize the error handler to prevent putting try-catch around every sql call command, which I have already done successfully, however, I am not sure how to re-execute the operation that caused the error? Is it possible to "retry" in .NET?

amindomeniko
  • 417
  • 6
  • 23
  • 1
    There's no magic "retry" command, but [this answer](http://stackoverflow.com/a/1563234/2091410) may help. Note that the answerer says "blanket CATCH statements can be dangerous". They're absolutely right. I don't recommend doing this, but that's your decision. – Ed Gibbs Feb 22 '16 at 15:30
  • @Ed Gibbs, thank you. I will look into this. – amindomeniko Feb 22 '16 at 18:32

1 Answers1

0

You can have a do while loop, with a Thread.sleep for specific number of seconds to retry. We acheive retry using this appraoch

Saravanan
  • 283
  • 2
  • 17
  • I totally understand this approach but I am trying to have a centralize catch so doing a while loop is not an option here because it would require putting the operation in this while loop in every place that a catch is required. – amindomeniko Feb 22 '16 at 18:31