解决.net core 使用 Microsoft.Data.SqlClient 连接低版本 sql server 问题

在使用 Microsoft.Data.SqlClient 连接sql server 2012 的时候,报了一个错误:

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)

.net core 程序是跑在 docker 上, 单独部署到本地IIS上的时候却没有这个错误,因此猜测可能是 docker 基础镜像环境问题。

解决方法,在 dockerfile 上加上2行,修改环境内 linux tls ssl 支持的最低版本。

FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base
# 下面2行
RUN sed -i 's/MinProtocol = TLSv1.2/MinProtocol = TLSv1.0/g' /etc/ssl/openssl.cnf
RUN sed -i 's/MinProtocol = TLSv1.2/MinProtocol = TLSv1.0/g' /usr/lib/ssl/openssl.cnf

重新 docker build 后,运行正常。

已禁用评论。