DotNet5在Docker中连接SqlServer2012,报错最大池超出
背景介绍
我的场景是,C# DotNet5程序在Docker Net5镜像中,链接SqlServer服务器,直接Open显示超时,执行命令报错:Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were in use and max pool size was reached.
但事实上,最大池并没有超出。
解决方案
FROM mcr.microsoft.com/dotnet/aspnet:5.0-buster-slim AS base
WORKDIR /app
# 配置 .NET 运行时强制使用旧版 TLS
ENV DOTNET_SYSTEM_NET_HTTP_USESOCKETSHTTPHANDLER=0
RUN sed -i 's/DEFAULT@SECLEVEL=2/DEFAULT@SECLEVEL=1/g' /etc/ssl/openssl.cnf
# 安装根证书(可选,解决 SSL 证书信任问题)
RUN apt-get update && \
apt-get install -y ca-certificates && \
update-ca-certificates
# 复制应用程序文件
COPY . .
ENTRYPOINT ["dotnet", "YourApp.dll"]