[解決方式] 此憑證鏈結是由不受信任的授權單位發出的

升級到 Entity Framework Core 7 後第一個遇到的錯誤:
    
Microsoft.Data.SqlClient.SqlException (0x80131904): A connection was successfully established with the server, but then an error occurred during the login process. (provider: SSL Provider, error: 0 - 此憑證鏈結是由不受信任的授權單位發出的。)
 ---> System.ComponentModel.Win32Exception (0x80090325): 此憑證鏈結是由不受信任的授權單位發出的。
    

原因是 Microsoft.Data.SqlClient 4.0 以後會驗證 SQL Server 憑證,最正確的方式是加上憑證來解決這個問題。

或是在連接字串後面加上 TrustServerCertificate=true; 讓其信任伺服器憑證也可以暫時解決,不會再拋出錯誤。
    
"DefaultConnection": "Server=localhost;Database=ruyut;User=ruyut;Password=ruyut;TrustServerCertificate=true;"
    


參考資料:
Microsoft.Learn - Login-phase errors

留言