I have a method that calls a SQLServer function to perform a free text search against a table. That function will occasionally on the first call result in a SQLException: \"
I'd change the exception handling to only retry on certain errors:
These are the basic "retryable" errors
catch (SqlException ex)
{
if !(ex.Number == 1205 || ex.Number == 1204 || ... )
{
throw
}
retryCount++;
if (retryCount > MAX_RETRY) throw;
}
Edit, I clean forgot about waits so you don't hammer the SQL box:
Edit 2:
I'm a Developer DBA, don't do much C#. My answer was to correct exception processing for the calls...
Pull the relevant code out into its own method, then use recursion.
Pseudo-code:
try
{
doDatabaseCall();
}
catch (exception e)
{
//Check exception object to confirm its the error you've been experiencing as opposed to the server being offline.
doDatabaseCall();
}