admin管理员组

文章数量:1122832

I have a .NET Core website where I've replaced the deprecated System.Data.SqlClient library with Microsoft.Data.SqlClient, and can no longer connect to the default SQL Server instance on my server.

I was originally using Server=localhost in the connection string, but since changing library this brings up the error message

The certificate received from the remote server does not contain the expected name. It is therefore not possible to determine whether we are connecting to the correct server. The server name we were expecting is localhost. The TLS connection request has failed.

I have a wildcard certificate for *.mydomain.example in place under SQL Server Configuration and 'Force Encryption' turned on, which was working fine, and still does for other sites using System.Data.SqlClient. Despite using localhost I assume that the encryption was working as when the certificate periodically expired, the SQL connection would fail.

I've added an A record to my DNS server for server.mydomain.example which points to 127.0.0.1, changed the connection string to Server=server.mydomain.example and I no longer get the original error. Instead I get

Named Pipes Provider, error: 40 - Could not open a connection to SQL Server

I've also tried adding an entry to the hosts file but get the same issue.

If I force TCP (as Named Pipes is disabled anyway) with Server=TCP:server.mydomain.example then I get

TCP Provider, error: 0 - The remote computer refused the network connection

Rolling back to the old library is the obvious fix, but I'd like to understand why it's not working.

本文标签: netCan39t connect to encrypted SQL Server connection using MicrosoftDataSqlClientStack Overflow