Issue with System.Data.SqlClient.SqlException differences between Win/Mac Fx/Core #1118
Description
Hi
We are facing an issue with difference in behavior between our Windows (based on FX) and Mac (based on .NET 5) implementation for connecting to SQL server. We are trying to make an encrypted connection to a server that doesn't support it.
In both environments we will receive a SqlException, but in windows, we receive -2146893019 as the Number of the error, and in Mac it is 0. We use this number to identify the specific exception (that the user is trying to connect to a non-secure server), but on Mac this is broken.
Is there a bug here in the .NET core implementation ? Is there an alternative way to get this done ?
Some more details.
In windows, we receive the following error message:
"{"A connection was successfully established with the server, but then an error occurred during the login process. (provider: SSL Provider, error: 0 - The certificate chain was issued by an authority that is not trusted.)"}"
ErrorCode: -2146232060
Source: ".Net SqlClient Data Provider"
Number: -2146893019
InnerException: {"The certificate chain was issued by an authority that is not trusted"} (System.Exception {System.ComponentModel.Win32Exception})
On Mac, we receive:
"A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: TCP Provider, error: 35 - An internal exception was caught)"
ErrorCode: -2146232060
Number: 0
InnerException: {System.Security.Authentication.AuthenticationException: The remote certificate was rejected by the provided RemoteCertificateValidationCallback. at System.Net.Security.SslStream.SendAuthResetSignal(ProtocolToken message, ExceptionDispatchInfo exception) at System.Net.Security.SslStream.ForceAuthenticationAsync[TIOAdapter](TIOAdapter adapter, Boolean receiveFirst, Byte[] reAuthenticationData, Boolean isApm) at System.Net.Security.SslStream.ProcessAuthentication(Boolean isAsync, Boolean isApm, CancellationToken cancellationToken) at System.Net.Security.SslStream.AuthenticateAsClient(SslClientAuthenticationOptions sslClientAuthenticationOptions) at System.Net.Security.SslStream.AuthenticateAsClient(String targetHost, X509CertificateCollection clientCertificates, SslProtocols enabledSslProtocols, Boolean checkCertificateRevocation) at System.Net.Security.SslStream.AuthenticateAsClient(String targetHost) at System.Data.SqlClient.SNI.SNITCPHandle.EnableSsl(UInt32 options)}
Source: Core .Net SqlClient Data Provider"
Activity