环境:dotnet 8 + sqlserver2012
本地开发调试正常,部署至Docker容器时,运行实例报错。
查看日志显示:
Unhandled exception. Microsoft.Data.SqlClient.SqlException (0x80131904): A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: SSd)
在数据库连接字符串中增加:TrustServerCertificate = true 也无法起效。
最终在官方SqlClient的issues找到解决方案
解决方案如下:在编译镜像的Dockerfile中增加如下配置即可
RUN sed -i 's/\[openssl_init\]/# [openssl_init]/' /etc/ssl/openssl.cnf RUN printf "\n\n[openssl_init]\nssl_conf = ssl_sect" >> /etc/ssl/openssl.cnf RUN printf "\n\n[ssl_sect]\nsystem_default = ssl_default_sect" >> /etc/ssl/openssl.cnf RUN printf "\n\n[ssl_default_sect]\nMinProtocol = TLSv1\nCipherString = DEFAULT@SECLEVEL=0\n" >> /etc/ssl/openssl.cnf
参考解决链接:https://github.com/dotnet/SqlClient/issues/2242#issuecomment-1858390282
标签:cnf,exception,0x80131904,openssl,SqlClient,ssl,报错,dotnet,RUN From: https://www.cnblogs.com/CXY-Blog/p/17974641