處理asp.net core連接mysql的一個異常Sequence contains more than one matching element


晚上在那里調程序,把mysql.data組件的nuget包進行了更新,前幾天好好的程序,開始拋錯,跟蹤斷點發現以下的異常:

Unable to connect to any of the specified MySQL hosts.
一開始以為數據庫出了錯誤,去檢查數據庫狀態正常,用Mysql workbench在遠程連接也正常。感覺有點奇怪。
又認真看了下,發現這個異常下面還有個提示:

INNER EXCEPTION:
Sequence contains more than one matching element

這是個什么鬼,網上搜索了一下,發現這個是mysql.data組件的一個bug
大意是在連接字符串使用了www.xxx.com這樣的域名來連接mysql.而mysql組件在解析時發現IP與以前訪問的Ip不一致,於是拒絕連接。

解決的辦法有幾個:

As I see it, you have three options:

  1. Downgrade to 8.0.17.
  2. Use your workaround of performing DNS resolution yourself, then using an IP address in the connection string.
  3. Switch MySQL libraries (to MySqlConnector).

如我所見,您有三個選擇:
1)降級至8.0.17。
2)使用您自己執行DNS解析的解決方法,然后在連接字符串中使用IP地址。
3)切換MySQL庫(到MySqlConnector)。

我選擇把連接字符串更改成IP的形式訪問,問題得到了解決。
但是這顯然不是一個最終解決的辦法。

官方提出:

Posted by developer:

Fixed as of the upcoming MySQL Connector/NET 8.0.20 release, and here's the proposed changelog entry from the documentation team:

A connection made to a named server with multiple DNS entries pointing to
different IP addresses for the same server generated an exception. Now,
only the first element is returned when multiple elements are found.

Thank you for the bug report.
在即將推出的MySQL Connector / NET 8.0.20版本中已修復,這是文檔團隊建議的changelog條目:

與指定服務器建立的連接,其中有多個DNS條目指向
同一服務器的不同IP地址生成異常。 現在,
找到多個元素時,僅返回第一個元素。

我在nuget服務器里看了下,8.0.20還沒有上線。只有等上線后再解決吧。


免責聲明!

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



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