Connection open error . Connection Timeout Expired. The timeout period elapsed during the post-login phase.
是这样的,最近我在开发Api(重构),用的数据库是Sqlserver,使用的Orm是 SqlSugar(别问我为什么选这个,boss选的同时我也想支持国人写的东西,且文档也很全)。
被催的是,写好了程序本地(windows10 pro 64 bit)运行正常,一部署到测试机器(centos7.2 64 bit)就报错:
报错1
An unhandled exception occurred while processing the request.
SqlSugarException: English Message : Connection open error . 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=48; handshake=124; [Login] initialization=0; authentication=0; [Post-Login] complete=14000;
Chinese Message : 连接数据库过程中发生错误,检查服务器是否正常连接字符串是否正确,实在找不到原因请先Google错误信息: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=48; handshake=124; [Login] initialization=0; authentication=0; [Post-Login] complete=14000; .
如图:
wtf!!!:为毛本地好好的,一丢到linux测试机(后面简称测试机)就出问题???
然后,我开始痛苦的排查了,从环境、框架,依赖注入,数据库网络;
telnet ping啊那些不用说了;
1、换台测试机 --> 测试机一样报错(排除本机玄学原因);
2、更新SqlSugar版本,从4.9.7更新到4.9.8.1--> 本地正常、测试机一样报错(基本排除驱动特地版本的bug);
3、用程序连接查询同网段的其他数据库 --> 本地正常、测试机一样报错(基本也排除网络原因);
4、连接我自己远程服务器的数据库 --> 本地正常、测试机正常--(排除linux驱动工作不正常或者程序时bug)
最后,我想想一直报超时。我都没增加超时时间(默认应该是15秒),我在连接字符串里面加了一个
Connect Timeout=300;//5分钟的超时时间
得,报的错变成了:
报错2
An unhandled exception occurred while processing the request.
SqlSugarException: English Message : Connection open error . A connection was successfully established with the server, but then an error occurred during the login process. (provider: TCP Provider, error: 35 - An internal exception was caught)
Chinese Message : 连接数据库过程中发生错误,检查服务器是否正常连接字符串是否正确,实在找不到原因请先Google错误信息:A connection was successfully established with the server, but then an error occurred during the login process. (provider: TCP Provider, error: 35 - An internal exception was caught).
SqlSugar.AdoProvider.GetDataReader(string sql, SugarParameter[] parameters)
如图:
各种玄学的非玄学的方法都找完了,差点想提前打包回家了,我突然灵光一闪??会不会数据库版本问题!!!
最后发现了这个,
.net core 的System.Data.SqlClient支持的最低SqlServer版本是2008 r2 SP3,小于这个版本的就会报这个错。
来源:
https://github.com/dotnet/corefx/issues/9719
结论:
.netcore 连接使用sqlserver遇到以上报错1、报错2的同学,需注意:.net core 的System.Data.SqlClient支持的最低SqlServer版本是2008 r2 SP3请先检查数据库版本。
呼~这个鬼问题浪费了我整整两天+(3个熬夜)。