【问题标题】:ArgumentException: Keyword not supported: 'server'ArgumentException:不支持关键字:“服务器”
【发布时间】:2017-09-13 17:41:54
【问题描述】:

我有一个 Asp.net MVC5 应用程序并已将其发布到Microsoft Azure。我首先将我的.mdf 文件迁移到Sql Azure DatabasesAzure Portal 中提供的数据库连接字符串不起作用。

[ArgumentException:不支持关键字:“服务器”。]

我的连接字符串如下web.config

connectionString="
    Server=tcp:dbprojectserver.database.windows.net,1433;
    Initial Catalog=db_project;
    Persist Security Info=False;
    User ID=username@servername;
    Password=kenth&&123;
    Encrypt=True;
    TrustServerCertificate=False;
    Connection Timeout=30;
    "

我相信这个连接字符串有问题。对此的任何帮助都非常感谢。

编辑

从这里阅读SQL Server Connection Strings 并遵循 EF Db first 或 Model first 连接字符串示例

<add name="ConnectionStringName"
    providerName="System.Data.EntityClient"
    connectionString="metadata=res://*/ ContextClass.csdl|res://*/ ContextClass.ssdl|res://*/ ContextClass.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=ServerName;Integrated Security=False;User Id=userid;Password=password;MultipleActiveResultSets=True&quot;" />

这是我根据上面的例子使用的

<add name="ProjectEntities" connectionString="metadata=res://*/ ProjectWeb.Models.User.csdl|res://*/ ProjectWeb.Models.User.ssdl|res://*/ ProjectWeb.Models.User.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=tcp:dbprojectserver.database.windows.net,1433;Integrated Security=False;User Id=username@servername;Password=kenth$$123;MultipleActiveResultSets=True&quot;
      " providerName="System.Data.EntityClient"/>

上面写着

关键字不支持“数据源”

【问题讨论】:

  • 你是怎么得到这个连接字符串的?这个真的是门户网站提供的吗?因为我查看了自己的几个示例,只看到“Data Source=".​​..",从未看到 Server=""
  • @Henk,是的,这就是门户网站提供的内容
  • @HenkHolterman 有几个关键字具有相同的含义。
  • 你见过这个吗:stackoverflow.com/a/6647089/1658906
  • @juunas,请参阅问题的编辑部分。

标签: sql asp.net-mvc azure deployment connection-string


【解决方案1】:

在应用程序服务设置(应用程序设置 -> 连接字符串)中在 Azure 门户上指定 EF 连接字符串时,我遇到了同样的问题。

修复它:

  • &amp;quot; 替换为"
  • 将连接字符串类型指定为 自定义,但不要指定为 SQL 数据库

另外,我可以看到您的最新示例中没有初始目录。您需要添加它并在此参数中指定您的数据库。

最后,Azure 门户中应用程序设置的连接字符串应如下所示:

metadata=res://*/ ProjectWeb.Models.User.csdl|res://*/ ProjectWeb.Models.User.ssdl|res://*/ ProjectWeb.Models.User.msl;
provider=System.Data.SqlClient;
provider connection string="Data Source=tcp:dbprojectserver.database.windows.net,1433;Initial Catalog=<your database>;Integrated Security=False;User Id=username@servername;Password=kenth$$123;MultipleActiveResultSets=True";

【讨论】:

    猜你喜欢
    • 2011-10-02
    • 2020-07-26
    • 2021-10-23
    • 2018-10-08
    • 1970-01-01
    • 1970-01-01
    • 2021-11-09
    • 2018-07-10
    • 1970-01-01
    相关资源
    最近更新 更多