异常处理-证书链是由不受信任的颁发机构颁发的

Microsoft.Data.SqlClient.SqlException (provider: SSL Provider, error: 0 - 证书链是由不受信任的颁发机构颁发的。)
异常内容描述

Microsoft.Data.SqlClient.SqlException
HResult=0x80131904
Message=A connection was successfully established with the server, but then an error occurred during the login process. (provider: SSL Provider, error: 0 - 证书链是由不受信任的颁发机构颁发的。)
Source=Core Microsoft SqlClient Data Provider
StackTrace:
在 Microsoft.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
...
内部异常 1:
Win32Exception: 证书链是由不受信任的颁发机构颁发的。

解决办法参考
https://learn.microsoft.com/zh-cn/troubleshoot/sql/database-engine/connect/certificate-chain-not-trusted?tabs=ole-db-driver-19

示例

 public const string ReadConnectString = "server=127.0.0.1;database=AdvancedDb;User ID=sa;Password=root;Trust Server Certificate=true";
posted @ 2023-02-10 14:20  壮哈苗  阅读(301)  评论(1编辑  收藏  举报