【问题标题】:Failing to get EF connection string to work when setup in Azure's management portal?在 Azure 的管理门户中设置时无法使 EF 连接字符串正常工作?
【发布时间】:2016-03-24 02:36:29
【问题描述】:

我正在使用部署在 WebApps、EF6、Azure SQL 数据库上的 ASP.NET MVC4

我有两个连接字符串,一个直接连接到数据库,一个在我使用实体框架时需要。如果我通过 Azure 设置第一个并将 EF 字符串保留在 web.config 中,一切正常。一旦我尝试将 EF 连接字符串移动到 Azure,它就会中断。

我已尝试关注有关如何在 Azure 管理门户中设置 EF 连接字符串的所有帖子,建议似乎是使用以下内容:

在管理门户中:

姓名:

EFConnectionString

价值:

metadata=res://MyModel/model.csdl|res://MyModel/model.ssdl|res://MyModel/model.msl;provider=System.Data.SqlClient;provider connection string="Data Source=tcp:myserver.database.windows.net,1234;Initial Catalog=mydatabase;User ID=Admin@myserver.database.windows.net;Password=12345678"

SQL 数据库:

Custom

注意:

" is replaced by " in the Azure string.

在 Web.config 中我仍然需要以下内容:

<add name="EFConnectionString" connectionString="" providerName="System.Data.EntityClient"/>

出于安全原因,我更改了连接字符串中的某些细节,但真正的字符串在 Web.config 中可以正常工作。

但是,当我尝试上述方法时,我得到:

The page cannot be displayed because an internal server error has occurred.

进一步的日志错误信息:

The specified named connection is either not found in the configuration, not intended to be used with the EntityClient provider, or not valid.

任何帮助表示赞赏。我正在尝试这样做以增强用于访问 Azure 上的数据库的存储密码的安全性,因为我知道通过门户设置它们会对其进行加密。

谢谢。

【问题讨论】:

  • 这一切对我来说真的很奇怪。为什么一个配置中的连接字符串在另一个 SqlClient 中使用 System.Data.EntityClient?为什么端口(我假设是 1234)用“,”而不是“:”分隔?
  • 借用stackoverflow.com/questions/14459748/…的建议首先检查是否在ConfigurationManager.ConnectionStrings中看到连接字符串(即写入网页)。该名称应存在于 web.config 中,Azure WS 将其替换为门户中定义的值(如果不存在则不会添加新的)。

标签: entity-framework azure entity-framework-6 azure-sql-database azure-web-app-service


【解决方案1】:

首先检查您的部署。我遇到了类似的问题,经过几个小时的努力,我发现我在部署时没有实际发送连接字符串,而是退回到门户配置中的任何内容...... we.config 中的其他键是发送过来了,但是 conn 字符串没有……在我在门户上正确设置之后,一切都恢复正常了……

【讨论】:

    猜你喜欢
    • 2016-08-02
    • 1970-01-01
    • 2016-09-13
    • 1970-01-01
    • 1970-01-01
    • 2013-01-05
    • 1970-01-01
    • 1970-01-01
    • 2020-04-14
    相关资源
    最近更新 更多