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中增加如下配置即可

1
2
3
4
5
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 @   咸鱼Y  阅读(393)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 25岁的心里话
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!
· 零经验选手,Compose 一天开发一款小游戏!
点击右上角即可分享
微信分享提示