We are using LocalDb for integration/unit testing of a .NET Core application. I have been using this solution for months and recently started getting sporadic errors. It seems to happen the first time the tests try to execute a linked server query. The linked server query is hitting another database on the same LocalDb instance on my local machine, i.e. there is not really a remote connection happening. I am at a loss of how else to troubleshoot.

To set up the linked server connection, we are doing a simple SP call, nothing has changed with this from when it was working consistently.

EXEC sp_addlinkedserver @server='{ServerName}'
  1. Encryption not supported on the client


    Test{redacted} Aborted: Exit code is -532462766 (Unhandled exception. System.Data.SqlClient.SqlException (0x80131904): Encryption not supported on the client.
OLE DB provider "SQLNCLI11" for linked server "(localdb)\MSSQLLocalDB" returned message "A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online.".
OLE DB provider "SQLNCLI11" for linked server "(localdb)\MSSQLLocalDB" returned message "Client unable to establish connection".
   at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   at System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean async, Int32 timeout, Boolean asyncWrite)
   at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource`1 completion, Boolean sendToPipe, Int32 timeout, Boolean asyncWrite, String methodName)
   at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
  1. A similar stack track with an SSL credentials error

Exception Info: System.Data.SqlClient.SqlException (0x80131904): SSL Provider: No credentials are available in the security package


It seems you are using always encrypted for some columns in the database. This is not supported or functional with linked servers (or other means of distributed queries), as documented here . Quote from that page:

"The following features don't work on encrypted columns:

Transactional or merge replication

Distributed queries (linked servers, OPENROWSET(T-SQL), OPENDATASOURCE(T-SQL))"

For Always Encryped (AE), the encryption/decryption of data is done by the client, the API on the client side. APIs that supports AE include ADO.NET, JDBC and ODBC. Linked Server uses OLEDB (the calling server is a client to the remote server), and OLEDB do not have the functionality to encrypt/decrypt for AE.

  • Thank you for the reply. I checked both databases involved and there doesn't seem to be any encrypted columns involved i.e. this returns no rows on both DBs SELECT * FROM sys.columns c WHERE c.encryption_type IS NOT NULL. I will say that our company turned on encrypted connections recently in our production DBs. My issue is happening on a local dev machine in LocalDB and I've been ensured that the production change shoudln't be effecting my localhost LocalDb connections. I'm not positive that is true given the error messages, but I cannot prove it either. – Dude0001 Nov 16 '20 at 13:00
  • Ah, I see. I was barking up the wrong tree, it seems. Sorry about that. I'll leave it to somebody who might have encountered this to reply. But just as clarification: does it fail only on first call, or on every call? Also, just as FWIW, avoid linked server (even if "loopback", or perhaps especially when loopback) whenever you can. :-) – Tibor Karaszi Nov 16 '20 at 13:45
  • Well, I'm doing unit testing, and the test fails after it hits this exception and doesn't try anything else. It doesn't happen every time but when it does, it is always on the same linked server query that happens early on in the test. Unfortunately, I don't have a lot of control of eliminating the linked server query, I would like to get rid of it myself. – Dude0001 Nov 16 '20 at 14:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.