在 .net core 3.1 的 docker 镜像生成的容器中,连接 sql server 2008 r2 版本的数据库,遇到错误
错误1:
{
"ClassName": "System.Data.SqlClient.SqlException",
"Message": "A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: TCP Provider, error: 35 - An internal exception was caught)",
"Data": {
"HelpLink.ProdName": "Microsoft SQL Server",
"HelpLink.EvtSrc": "MSSQLServer",
"HelpLink.EvtID": "0",
"HelpLink.BaseHelpUrl": "https://go.microsoft.com/fwlink",
"HelpLink.LinkId": "20476",
"SqlError 1": "System.Data.SqlClient.SqlError: A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: TCP Provider, error: 35 - An internal exception was caught)"
},
"InnerException": {
"ClassName": "System.Security.Authentication.AuthenticationException",
"Message": "Authentication failed, see inner exception.",
"Data": null,
"InnerException": {
"StackTrace": " at Interop.OpenSsl.DoSslHandshake(SafeSslHandle context, Byte[] recvBuf, Int32 recvOffset, Int32 recvCount, Byte[]& sendBuf, Int32& sendCount)\n at System.Net.Security.SslStreamPal.HandshakeInternal(SafeFreeCredentials credential, SafeDeleteContext& context, ArraySegment`1 inputBuffer, Byte[]& outputBuffer, SslAuthenticationOptions sslAuthenticationOptions)",
"Message": "SSL Handshake failed with OpenSSL error - SSL_ERROR_SSL.",
"Data": {},
"InnerException": {
"StackTrace": null,
"Message": "error:1425F102:SSL routines:ssl_choose_client_version:unsupported protocol",
"Data": {},
"InnerException": null,
"HelpLink": null,
"Source": null,
"HResult": 338030850
},
"HelpLink": null,
"Source": "System.Net.Security",
"HResult": -2146233088
},
问题和解决方法:
应该是 SQL Server 2008 R2 或其所在服务器支持的加密协议版本过低(不再安全),新版客户端已不再支持。
修改容器中 openssl 文件配置的最低允许使用的协议版本即可:
sed -i -e "s|^MinProtocol = .*|MinProtocol = TLSv1.0|g" "/etc/ssl/openssl.cnf"
另附,查询当前系统支持的加密协议:
openssl ciphers -v | awk '{print $2}' | sort | uniq
但解决了上一个问题,接下来就遇到了
错误2:
{
"ClassName": "System.Data.SqlClient.SqlException",
"Message": "Connection Timeout Expired. The timeout period elapsed during the post-login phase. The connection could have timed out while waiting for server to complete the login process and respond; Or it could have timed out while attempting to create multiple active connections. The duration spent while attempting to connect to this server was - [Pre-Login] initialization=0; handshake=9; [Login] initialization=0; authentication=0; [Post-Login] complete=14454; ",
"Data": {
"HelpLink.ProdName": "Microsoft SQL Server",
"HelpLink.EvtSrc": "MSSQLServer",
"HelpLink.EvtID": "-2",
"HelpLink.BaseHelpUrl": "https://go.microsoft.com/fwlink",
"HelpLink.LinkId": "20476",
"SqlError 1": "System.Data.SqlClient.SqlError: Connection Timeout Expired. The timeout period elapsed during the post-login phase. The connection could have timed out while waiting for server to complete the login process and respond; Or it could have timed out while attempting to create multiple active connections. The duration spent while attempting to connect to this server was - [Pre-Login] initialization=0; handshake=9; [Login] initialization=0; authentication=0; [Post-Login] complete=14454; "
},
"InnerException": {
"ClassName": "System.ComponentModel.Win32Exception",
"Message": "Unknown error 258",
"Data": null,
"InnerException": null,
"HelpURL": null,
"StackTraceString": null,
"RemoteStackTraceString": null,
"RemoteStackIndex": 0,
"ExceptionMethod": null,
"HResult": -2147467259,
"Source": null,
"WatsonBuckets": null,
"NativeErrorCode": 258
},
问题和解决方法:
暂未找到,同样的程序在 windows 下暂未遇到此问题。
输了你,赢了世界又如何...
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
2020-04-30 如何查看 github 上项目的大小