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; .

如圖:

1548216470015

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)

如圖:

1548216155789

各種玄學的非玄學的方法都找完了,差點想提前打包回家了,我突然靈光一閃??會不會數據庫版本問題!!!

最后發現了這個,

.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個熬夜)。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM