Repository navigation
ArgumentException: The specified value is not valid in the 'NativeProtocols' enumeration. #3120
Copy link
Copy link
Closed
Closed
Copy link
Labels
Regression 💥Issues that are regressions introduced from earlier PRs.Issues that are regressions introduced from earlier PRs.
Milestone
Description
Describe the bug
SqlClient throws an exception when opening the connection.
System.ArgumentException
HResult=0x80070057
Message=The specified value is not valid in the 'NativeProtocols' enumeration.
Parameter name: NativeProtocols
Source=Microsoft.Data.SqlClient
StackTrace:
at Microsoft.Data.SqlClient.SslProtocolsHelper.ToFriendlyName(SslProtocols protocol) in /_/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/TdsParserHelperClasses.cs:line 809
at Microsoft.Data.SqlClient.SslProtocolsHelper.GetProtocolWarning(SslProtocols protocol) in /_/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/TdsParserHelperClasses.cs:line 837
at Microsoft.Data.SqlClient.TdsParser.EnableSsl(UInt32 info, SqlConnectionEncryptOption encrypt, Boolean integratedSecurity, String serverCertificate) in /_/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/TdsParser.cs:line 1250
at Microsoft.Data.SqlClient.TdsParser.ConsumePreLoginHandshake(SqlAuthenticationMethod authType, SqlConnectionEncryptOption encrypt, Boolean trustServerCert, Boolean integratedSecurity, Boolean& marsCapable, Boolean& fedAuthRequired, Boolean tlsFirst, String serverCertificateFilename) in /_/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/TdsParser.cs:line 1513
at Microsoft.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, TimeoutTimer timeout, SqlConnectionString connectionOptions, Boolean withFailover, Boolean isFirstTransparentAttempt, Boolean disableTnir) in /_/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/TdsParser.cs:line 723
at Microsoft.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, TimeoutTimer timeout, Boolean withFailover, Boolean isFirstTransparentAttempt, Boolean disableTnir) in /_/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlInternalConnectionTds.cs:line 2309
at Microsoft.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString connectionOptions, SqlCredential credential, TimeoutTimer timeout) in /_/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlInternalConnectionTds.cs:line 1863
at Microsoft.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(TimeoutTimer timeout, SqlConnectionString connectionOptions, SqlCredential credential, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance) in /_/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlInternalConnectionTds.cs:line 1729
at Microsoft.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, DbConnectionPool pool, String accessToken, Boolean applyTransientFaultHandling, Func`3 accessTokenCallback) in /_/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlInternalConnectionTds.cs:line 534
at Microsoft.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) in /_/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlConnectionFactory.cs:line 147
at Microsoft.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions) in /_/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionFactory.cs:line 153
at Microsoft.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) in /_/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionPool.cs:line 906
at Microsoft.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) in /_/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionPool.cs:line 1975
at Microsoft.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection) in /_/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionPool.cs:line 1369
at Microsoft.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) in /_/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionPool.cs:line 1261
at Microsoft.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection) in /_/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionFactory.cs:line 306
at Microsoft.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) in /_/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionInternal.cs:line 972
at Microsoft.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) in /_/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionClosed.cs:line 43
at Microsoft.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry) in /_/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlConnection.cs:line 2160
at Microsoft.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry, SqlConnectionOverrides overrides) in /_/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlConnection.cs:line 2129
at Microsoft.Data.SqlClient.SqlConnection.Open(SqlConnectionOverrides overrides) in /_/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlConnection.cs:line 1674
at Microsoft.Data.SqlClient.SqlConnection.Open() in /_/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlConnection.cs:line 1644
Stepping into the code, the value of protocol is 128 which indeed doesn't match any of the SslProtocols
To reproduce
using var connection = new SqlConnection("data source=10.1.1.69;encrypt=optional;initial catalog=TEST");
connection.Open();Expected behavior
It just works.
Further technical details
Microsoft.Data.SqlClient version: 6.0.0
.NET target: .NET Framework 4.8
SQL Server version: SQL Server 2012
Operating system: Windows Server 2012
Additional context
Microsoft.EntityFramework.SqlServer version: 6.5.1
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Regression 💥Issues that are regressions introduced from earlier PRs.Issues that are regressions introduced from earlier PRs.
Activity
ErikEJ commentedon Jan 17, 2025
Wonder if support for SQL Server 2012 is broken - have you tried with a newer server version?
cheenamalhotra commentedon Jan 17, 2025
Can you also check if this is a recent issue or also occurs with MDS 5.2.2?
austinw-fineart commentedon Jan 17, 2025
No such problem on SQL Server 2022. No idea on other versions. A production server was running 2012 which is why I had to rollback to 5.2.2, no issues on that version. I went through the changelog but nothing indicates such a change. I looked through the file history in question and I believe #2376 is what broke it. The old code has a NativeProtocols enum and my 128 would have represented SP_PROT_TLS1_0_CLIENT. The new code only uses SslProtocols which appears to combine flags instead so it doesn't get matched.
SqlClient/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/TdsParserHelperClasses.cs
Lines 1312 to 1374 in a985927
SqlClient/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/TdsParserHelperClasses.cs
Lines 760 to 810 in c0bc846
edwardneal commentedon Jan 17, 2025
Thanks for the pointer - you're correct, #2376 introduced the problem. This only occurs when using .NET Framework to connect to a SQL Server instance using an encryption protocol other than TLS 1.2. Enabling TLS 1.2 resolves this - the most recent CU for SQL Server 2008 upwards introduces support.
This only occurs on .NET Framework because it looks like the SSL protocol values are reported differently between the native and the managed SNIs, and I didn't pick up on that difference. This should probably have been tested by the
CertificateTestWithTdsServerclass, but the TDS server we use for testing always uses TLS 1.2. Sorry for the gap here.I'll submit a PR shortly which fixes and tests this.
edwardneal commentedon Jan 24, 2025
@austinw-fineart SqlClient 6.0.1 was released earlier today, and it should contain the bugfix. Can you re-test with this version please?
cheenamalhotra commentedon Jan 26, 2025
Closing as issue has been addressed in 6.0