開發環境
- Visual Studio 2022 v17.6
- ASP.NET Core MVC (.NET 6)
- Entity Framework Core 7.x
問題
在執行 Update-Database 的 Migration 指令時出現資料庫憑證錯誤的訊息,使得更新資料庫失敗。
錯誤訊息如下:
A connection was successfully established with the server, but then an error occurred during the login process. (provider: SSL Provider, error: 0 - 此憑證鏈結是由不受信任的授權單位發出的。)
在本機端開發第一次遇到連線字串需要憑證的問題,過往是連遠端資料庫才會有憑證要求,特此記錄一下。
解決方法
一種是在連線字串後加上 Encrypt=False;
不採用加密連線
另一種方式是主動信任 SQL Server 的憑證 TrustServerCertificate=True;
在本機開發階段連線不加密或是主動信任憑證是還好,在生產主機上連線就依正常加密及正確的憑證吧!