dotnet 8项目Docker部署报错 Unhandled exception. Microsoft.Data.SqlClient.SqlException (0x80131904) 解决方案

环境: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

 

posted @ 2024-01-19 14:59  咸鱼Y  阅读(163)  评论(0编辑  收藏  举报