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

通过CLI传递连接字符串更新多租户数据库时遇格式错误

解决方法

问题出在你使用了错误的EF Core CLI参数名:--connection-string不是EF Core识别的参数,正确的参数应该是--connection(或简写-c)。

正确的命令格式

执行以下命令即可:

dotnet ef database update -- --connection "Server=localhost,1433; Database=test; User Id=SA; Password=myPassword"

或者省略--(当不需要区分命令参数和工具参数时):

dotnet ef database update --connection "Server=localhost,1433; Database=test; User Id=SA; Password=myPassword"

报错原因

EF Core CLI无法识别--connection-string参数,导致没有正确传递连接字符串值,最终解析时拿到的是无效的初始化字符串(甚至是空值),从而抛出格式错误。你的连接字符串本身是正确的(Azure Data Studio能连接验证了这一点),只需要修正参数名即可。

额外提示

如果你的项目有多个DbContext,需要通过--context参数指定要使用的上下文:

dotnet ef database update --connection "你的连接字符串" --context YourDbContextName

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.08 05:42:51