SQLClient What error numbers are related to SQL Server Connection errors so I can retry

datadev picture datadev · Sep 29, 2014 · Viewed 9.7k times · Source

I get the following error with SQLClient, are there more error numbers than Error Number: -1, 53, 2?

Error Number: -1, Level: 20, State: 0, Line: 0; Message: 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: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)

Error Number: 53, Level: 20, State: 0, Line: 0; Message: 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)

Error Number: 2, Level: 20, State: 0, Line: 0; Message: 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)

Answer

user2864740 picture user2864740 · Sep 15, 2017

The rules I use for general classification:

  • Number = -1 OR Class/Level/Severity = 20: "Connection Error"

  • Number = -2: "Command Timeout Error"

I believe the negative values are strictly from the client library (ie. network connection issues); this implies the "duplicate" numbers like 2 and 53 come back from the server itself for half-connections.

Other errors (eg. deadlocks/1205) can be more readily defined by the Number.


As the other answer contains, here is also a link to various references: