EF Core连接SQL Server登录报错:证书链不受信任问题排查
问题原因解析
1. 身份验证参数冲突
你的连接字符串同时配置了两种互斥的身份验证方式:
user id=SPMS-User;password=*********:指定SQL Server账号密码认证Trusted_Connection=True:指定Windows集成认证
这两个参数不能同时存在,SQL Server无法确定使用哪种认证逻辑,直接触发登录阶段的异常。
2. SSL证书信任问题
报错信息里的SSL Provider, error: 0 - The certificate chain was issued by an authority that is not trusted,原因是:
SQL Server默认启用加密连接要求,但本地部署的SQL Server一般使用自签名证书,这类证书未被客户端(你的桌面应用)的系统信任根证书库收录,导致客户端拒绝信任该证书,中断连接流程。
修正建议(附示例)
方案1:使用SQL Server账号认证
移除Trusted_Connection=True,添加TrustServerCertificate=True跳过证书信任验证:
protected override void OnConfiguring(DbContextOptionsBuilder options) { options.UseSqlServer(@"data source=.;initial catalog=SpmsTwoSuctionOneThrust;user id=SPMS-User;password=*********;TrustServerCertificate=True;"); }
方案2:使用Windows集成认证
移除user id和password参数,保留Trusted_Connection=True并添加证书信任配置:
protected override void OnConfiguring(DbContextOptionsBuilder options) { options.UseSqlServer(@"data source=.;initial catalog=SpmsTwoSuctionOneThrust;Trusted_Connection=True;TrustServerCertificate=True;"); }
内容的提问来源于stack exchange,提问作者hmahdavi
相关产品推荐
相关产品推荐

