I have created a C# .NET 4.7 application that connects to several different remote SQL database instances. Sometimes connection issues may prevent the connection at a network level.
Presently I'm handling SQL timeout connections with the below code which works fine if a connection exists, but if the issue is at the network level I need to handle these, of which the timeouts are much longer.
I found an article written over 10 years ago here http://improve.dk/controlling-sqlconnection-timeouts/. I was wondering if anyone could recommend whether this is current best practice or whether there is a better solution?
if ( e is SqlException f)
{
if (f.Number == -2 | f.Number == 258)
{ do stuff}
}