【发布时间】: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