SqlClient cannot connect to Azure SQL db from a Nano Server machine
I have a small web app which works fine from Windows 10 or Ubuntu hosts. When I run it on a Nano Server (2016 TP5) machine, though, connecting to an Azure SQL database (via EF.Core) fails with this exception:
An exception occurred in the database while iterating the results of a query.
System.Data.SqlClient.SqlException: The instance of SQL Server you attempted to connect to requires encryption but this machine does not support it.
at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, Bo
olean applyTransientFaultHandling)
at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions)
at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection)
at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection)
at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
at System.Data.SqlClient.SqlConnection.Open()
at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.Open()
at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable.Enumerator.MoveNext()
at Microsoft.EntityFrameworkCore.Query.QueryMethodProvider.GetResult[TResult](IEnumerable`1 valueBuffers)
at lambda_method(Closure , QueryContext )
at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.<>c__DisplayClass19_1`1.<CompileQuery>b__1(QueryContext qc)
ClientConnectionId:ca7143d2-0c75-4a31-a770-a46d781c9d57
Error Number:20,State:0,Class:20
System.Data.SqlClient.SqlException: The instance of SQL Server you attempted to connect to requires encryption but this machine does not support it.
at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, Boolean
applyTransientFaultHandling)
at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions)
at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection)
at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection)
at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
at System.Data.SqlClient.SqlConnection.Open()
at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.Open()
at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable.Enumerator.MoveNext()
at Microsoft.EntityFrameworkCore.Query.QueryMethodProvider.GetResult[TResult](IEnumerable`1 valueBuffers)
at lambda_method(Closure , QueryContext )
at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.<>c__DisplayClass19_1`1.<CompileQuery>b__1(QueryContext qc)
The connection string I'm using is:
Server=tcp:iasveotbxa.database.windows.net,1433;Database=mikerou-widgets;User ID=ReproAdmin@iasveotbxa;Password=*****;Connection Timeout=300
I've tried explicitly adding both Encrypt=false and Encrypt=true to the connection string, but neither helps.
Is this perhaps just a nano server limitation or is there something that can be done either in my code or in System.Data.SqlClient to make this work?
cc: @Priya91
Email from @corivera Looks like the failures are caused by a DLL load failure. SqlClient tries to load security.dll to handle encryption, but that DLL doesn’t exist on Nano. That eventually manifests as an “encryption not supported” error. We may be able to just use schannel.dll for encryption on Nano, and I’m looking into that as a workaround.
Secur32.dll appears to be the correct alternative to use according to the Windows SSPI documentation. My test connections from Nano to Azure succeed when using that dll
@corivera
My test connections from Nano to Azure succeed when using that dll
Did you drop a sni.dll compiled with secur32.dll to make this work?
@saurabh500 Yep
Any updates on getting these calls redirected to Secur32 in Nano cases?
I am using 1.1 framework and am still getting error.. Has this issue being resolved for nano on 1.1
An unhandled exception has occurred: The instance of SQL Server you attempted to connect to requires encryption but this machine does not support it. System.Data.SqlClient.SqlException: The instance of SQL Server you attempted to connect to requires encryption but this machine does not support it.
@corivera I am using Nano container image for my app.. any idea how you could do "did you drop a sni.dll compiled with secur32.dll to make this work? for the image..
Is there an update to this issue or is there a loctation to download a corrected version of sni.dll? Or even instructions on how to manually compile it?
SNI.dll has been fixed to allow Azure connectivity.
@saurabh500 where is this fixed deployed? I have this issue on a aspnetcore1.1-nanoserver based container in Service Fabric.
@stickybun You can get it via System.Data.SqlClient 4.4.0-preview1-25305-02 and later.