Feature | Error messages are not meaningful when target SQL server doesn't support 'Strict' encryption mode
- Dominant language
- C#
- Stars
- 989
- Forks
- 340
- Avg merge
- 4d 18h
- Merged PRs (30d)
- 69
Description
### Describe the bug
With 'Strict' encryption is requested, error messages don't provide useful information to what went wrong.
1. When connecting to a SQL Server 2019 instance that doesn't support 'Encrypt=Strict'
```
Microsoft.Data.SqlClient.SqlException (0x80131904): The client was unable to establish a connection because of an error during connection initialization process before login.
Possible causes include the following: the client tried to connect to an unsupported version of SQL Server; the server was too busy to accept new connections; or there was a resource limitation (insufficient memory or maximum allowed connections) on the server.
(provider: SSL Provider, error: 0 - The wait operation timed out.)
---> System.ComponentModel.Win32Exception (258): The wait operation timed out.
at Microsoft.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
at Microsoft.Data.SqlClient.TdsParser.EnableSsl(UInt32 info, SqlConnectionEncryptOption encrypt, Boolean integratedSecurity)
at Microsoft.Data.SqlClient.TdsParser.SendPreLoginHandshake(Byte[] instanceName, SqlConnectionEncryptOption encrypt, Boolean integratedSecurity)
at Microsoft.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, SqlConnectionString connectionOptions, Boolean withFailover)
...
Error Number:258,State:0,Class:20
```
2. When connecting to a SQL Server 2022 instance that is not configured with TLS certificate, but 'Strict' encryption is requested.
```
Microsoft.Data.SqlClient.SqlException (0x80131904): The client was unable to establish a connection because of an error during connection initialization process before login.
Possible causes include the following: the client tried to connect to an unsupported version of SQL Server; the server was too busy to accept new connections; or there was a resource limitation (insufficient memory or maximum allowed connections) on the server.
(provider: SSL Provider, error: 0 - No process is on the other end of the pipe.)
---> System.ComponentModel.Win32Exception (233): No process is on the other end of the pipe.
at Microsoft.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
at Microsoft.Data.SqlClient.TdsParserStateObject.SNIWritePacket(PacketHandle packet, UInt32& sniError, Boolean canAccumulate, Boolean callerHasConnectionLock, Boolean asyncClose)
at Microsoft.Data.SqlClient.TdsParserStateObject.WriteSni(Boolean canAccumulate)
at Microsoft.Data.SqlClient.TdsParserStateObject.WritePacket(Byte flushMode, Boolean canAccumulate)
at Microsoft.Data.SqlClient.TdsParser.SendPreLoginHandshake(Byte[] instanceName, SqlConnectionEncryptOption encrypt, Boolean integratedSecurity)
at Microsoft.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, SqlConnectionString connectionOptions, Boolean withFailover)
...
Error Number:233,State:0,Class:20
```
### Expected behavior
Throw an appropriate error message - as it can be identified from connection properties that user requested 'Strict' encryption and an SSL provider related error has occurred.
### Further technical details
Microsoft.Data.SqlClient version: 5.0.1
.NET target: .NET 6
SQL Server version: SQL 2019, 2022
Operating system: Windows 11 (Native SNI)
### Additional Context
I haven't tested Managed SNI yet, but that should be fixed to provide correct error messages too.
Contributor guide
Assessment
This issue has not been assessed yet.