【问题标题】:Connection string keyword 'server' is not Supported不支持连接字符串关键字“服务器”
【发布时间】:2021-11-09 02:21:42
【问题描述】:

我正在 MacBook 上部署一个带有 VS2017 的 ASP.NET Core MVC 应用程序。当我想更新我的数据库时

dotnet ef database update  --project MyProjectName

我收到一个错误:

不支持连接字符串关键字“服务器”。有关可能的替代方案,请参阅https://go.microsoft.com/fwlink/?linkid=2142181

我已经在我的项目中安装了System.Data.SqlClient 包,并且我已经阅读了类似的问题,但没有一个能解决我的问题。这段代码有什么问题?我真的很困惑。

"ConnectionStrings": {
    "DefaultConnection": "Server=my_ip; Database=my_db; User Id=sa; Password=my_pass;",
    "providerName": "System.Data.SqlClient"
  },
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft": "Warning",
      "Microsoft.Hosting.Lifetime": "Information"
    }
  },
  "AllowedHosts": "*"
}

【问题讨论】:

  • 嗨,有趣,也许用 Uri 代替?
  • 嗨@jspcal。感谢您的评论。我尝试了所有方法,甚至我使用过Data SourceInitial Catalog,但没有任何改变

标签: c# sql-server asp.net-core .net-core connection-string


【解决方案1】:

对于 SQL Server,试试这个连接字符串:

"DefaultConnection": "Data Source=35.xx.xx.xxxx;Initial Catalog=nmmm;Integrated Security=False;User ID=nmmm;Password=vvvvv;"

添加如果你使用 sql server 你应该在启动时有这个

services.AddDbContext<DbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));

【讨论】:

  • 谢谢谢尔盖。这样错误变为Connection string keyword 'initial catalog' is not supported
  • 你用的是什么数据库?
  • 是Sql server @Serge
  • @BehzadHassani 你也可以发布你的启动文件吗?
  • @BehzadHassani 为什么链接会显示 SQLIte?
猜你喜欢
  • 2018-07-10
  • 1970-01-01
  • 2011-10-02
  • 2011-12-30
  • 2021-12-07
  • 1970-01-01
  • 1970-01-01
  • 2020-07-26
  • 2021-10-23
相关资源
最近更新 更多