runtime: A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: SSL Provider, error: 31 - Encryption(ssl/tls) handshake failed) Mac OSX High Sierra 10.13.5

In PowerShell I try to test an SQL connection from a Mac OSX 10.13.5. DotNet Core and PowerShell were installed through homebrew.

$sqlStr = 'Data Source=SERVER;Initial Catalog=DB;Integrated Security=False;User ID=USER;Password=PASSWORD;Connect Timeout=30;Encrypt=False;TrustServerCertificate=True;'
$sqlConn = New-Object System.Data.SqlClient.SqlConnection $sqlStr
$con = $sqlConn.Open()

And I get this error:

A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: SSL Provider, error: 31 - Encryption(ssl/tls) handshake failed)

dotnet --version : 2.1.300 $PSVersionTable

Name                           Value
----                           -----
PSVersion                      6.1.0-preview.2
PSEdition                      Core
GitCommitId                    v6.1.0-preview.2
OS                             Darwin 17.6.0 Darwin Kernel Version 17.6.0: Tue May  8 15:22:16 PDT 2018; root:xnu-4570.61.1~1/RELEASE_X86_64
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 26 (3 by maintainers)

Most upvoted comments

Sorry, my mistake getting A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: HTTP Provider, error: 0 - )

I got this error last week following change of one of our application to upgrade dot net core 3.1. This quick fix was to change the connection string to add this configuration ;TrustServerCertificate=true

Look like default behavior has changed between 2.2 and 3.1

Hope that will help you

Hi @keeratsingh the same issue on the CentOS 7

sdk 2.1.302 net core 2.1.2

Was problem with nuget v3 but fix DOTNET_SYSTEM_NET_HTTP_USESOCKETSHTTPHANDLER=false works.

And now

Retrying ‘FindPackagesByIdAsync’ for source ‘https://api.nuget.org/v3-flatcontainer/microsoft.visualstudio.web.codegeneration.design/index.json’. The SSL connection could not be established, see inner exception. error:2006D002:BIO routines:BIO_new_file:system lib Retrying ‘FindPackagesByIdAsync’ for source ‘https://api.nuget.org/v3-flatcontainer/microsoft.aspnetcore.all/index.json’.

System.Data.SqlClient.SqlException : A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: SSL Provider, error: 31 - Encryption(ssl/tls) handshake failed) ---- Interop+Crypto+OpenSslCryptographicException : error:2006D002:BIO routines:BIO_new_file:system lib Stack Trace: 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)

I was having this issue connecting to SQL running in a docker container via SQL Ops Studio on my laptop running Ubuntu 16.04 (logged as a bug here: - https://github.com/Microsoft/sqlopsstudio/issues/2150). It was resolved by running: - sudo update-ca-certificates --fresh

Hello, I am still having this issue on centos 7 with net core sdk 2.1.302:

os version

cat /etc/*-release

CentOS Linux release 7.5.1804 (Core)
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"

CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"

CentOS Linux release 7.5.1804 (Core)
CentOS Linux release 7.5.1804 (Core)

net core version

dotnet --info

.NET Core SDK (reflecting any global.json):
 Version:   2.1.302
 Commit:    9048955601

Runtime Environment:
 OS Name:     centos
 OS Version:  7
 OS Platform: Linux
 RID:         centos.7-x64
 Base Path:   /usr/share/dotnet/sdk/2.1.302/

Host (useful for support):
  Version: 2.1.2
  Commit:  811c3ce6c0

.NET Core SDKs installed:
  2.1.302 [/usr/share/dotnet/sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.1.2 [/usr/share/dotnet/shared/Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.2 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.1.2 [/usr/share/dotnet/shared/Microsoft.NETCore.App]

systemd service definition

cat /etc/systemd/system/myservice-dev.service

[Unit]
Description=myservice
After=network.target

[Service]
WorkingDirectory=/usr/local/myservice-dev
ExecStart=/usr/bin/dotnet /usr/local/myservice-dev/webserviceproject.dll
Restart=always
# Restart service after 10 seconds if dotnet service crashes
RestartSec=10
SyslogIdentifier=myservice-dev
User=myserviceuser
Environment=ASPNETCORE_ENVIRONMENT=Production

[Install]
WantedBy=multi-user.target

if the user running the service is set to root then there is no exception thrown, with any other user this exception is thrown:

System.Data.SqlClient.SqlException (0x80131904): A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: SSL Provider, error : 31 - Encryption(ssl/tls) handshake failed) —> Interop+Crypto+OpenSslCryptographicException: error:2006D002:BIO routines:BIO_new_file:system lib

I am seeing the same issue running .NET Core 2.1.300.