You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

SqlClient忽略连接字符串User ID,始终使用集成安全性问题排查

问题根源与解决方案

你的问题核心是连接字符串中重复定义了Integrated Security参数:

  • 你先设置了Integrated Security=false,但后续又追加了Integrated Security=SSPI
  • SSPI等价于Integrated Security=True,且连接字符串中后出现的参数会覆盖前面的配置,最终生效的是集成安全模式,导致你设置的User ID和Password被完全忽略

修正后的连接字符串

删除重复的Integrated Security=SSPI,仅保留Integrated Security=false:

<add name="dbConString" connectionString="Server=dbServerName;Database=databaseName;User ID=sqlUserName; Password=sqlUserPassword; Integrated Security=false; TrustServerCertificate=True;" providerName="System.Data.SqlClient" />

额外检查项

  • 确认DbContext没有被其他配置覆盖:比如Program.cs/Startup.cs中是否存在硬编码的UseSqlServer配置,这类配置优先级会高于OnConfiguring中的设置
  • 验证ConfigurationManager是否正确读取到App.config的连接字符串:可以在OnConfiguring方法中添加断点或日志,确认读取到的字符串内容与配置一致

内容的提问来源于stack exchange,提问作者Martin M

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.09 19:48:10