Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible that SqlException is thrown and property Number == 0?

Is it possible that SqlException will be thrown when trying to execute sql procedure and property Number will be 0?

Specific situation: domain controller is not available/not responding and no real communication with sql server occurred.

like image 705
Tomasz Cyborowski Avatar asked Oct 22 '25 17:10

Tomasz Cyborowski


1 Answers

No, it should not be possible that SqlException.Number is 0, except for the following cases:

  • Read-only routing failure
  • Server had severe error processing query
  • Processed cancellation while parsing results
  • Failed to create user instance

Assuming you're not using read-only routing of SQL Server 2016, then none of these cases could apply to the scenario you described.

Remaining cases are either a non-zero number from sysmessages, or a Win32 error code (which, since 0 == ERROR_SUCCESS, would also never be zero).

In practice you will see something along the lines of "Cannot create SSPI context", or "A transport-level error has occurred when sending the request to the server", or a "An existing connection was forcibly closed by the remote host", and those have nonzero Win32 error codes too.

Reference: https://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlerror.number(v=vs.110).aspx

It may be worth noting that SqlException.Number is synonym for the Number property of the first entry in its Errors array, and that array might contain more than one item.

like image 134
Cee McSharpface Avatar answered Oct 24 '25 08:10

Cee McSharpface