I have a C# application that needs to connect to a SQL Server DB hosted by Amazon's RDS. Fairly often it throws the error
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
When it does this, it usually works on the next try. So I would like to add a programmatic "retry" to the queries in my app. I think that this (https://stackoverflow.com/a/4822976/1011724) looks like a good pattern to follow for this. However, that answer only retries for the following errors:
private enum RetryableSqlErrors
{
Timeout = -2,
NoLock = 1204,
Deadlock = 1205,
WordbreakerTimeout = 30053,
}
So is there a way to simply add this error? If so, what is the error code? Looking here (https://msdn.microsoft.com/en-us/library/cc645611.aspx), there is no error 40 and it also is not the exact wording of error -1.
Is my error a SqlException
? If so what number? If not, how can I adapted the code from the answer linked above to account for this type of exception?