[英]How do I set an ADO.NET Entity Framework connection string via the Windows Azure (Preview) Management Portal?
在Windows Azure(预览版)管理门户中,您可以更改网站的配置选项(请参见http://www.windowsazure.com/en-us/manage/services/web-sites/how-to-configure-websites/ #howtochangeconfig )。
我目前通过Web.Release.Config为ADO.NET实体框架连接设置了连接字符串,但是我想通过管理门户进行设置,但是无论使用什么,我总是会遇到以下错误:
在配置中找不到指定的命名连接,或者不打算与EntityClient提供程序一起使用,或者无效。
它确实适用于常规连接字符串,即无需元数据密钥定义元数据和映射信息(csdl,ssdl,msl)。
这是我的工作:
在“连接字符串”下,我有一个名为“ ApplicationServices”的键,如下所示:
服务器= tcp:xxxxx.database.windows.net,1433;数据库= xxxxx;用户ID = xxxxx @ xxxxx;密码= xxxxx; Trusted_Connection = False;加密= True;连接超时= 30;
这个作品。
我还有另一个用于实体框架连接的密钥。 我们称其为FooBarContext。 看起来像这样:
元数据= res:// /Models.FooBarContext.csdl|res:// /Models.FooBarContext.ssdl|res://*/Models.FooBarContext.msl;provider=System.Data.SqlClient;provider连接字符串=“ Server = tcp:fooserver.database.windows.net,1433;数据库= foobar;用户ID = myname @ fooserver;密码= xxxxxxxxxx; Trusted_Connection = False;加密= True;连接超时= 30;“
这会导致上述错误。 它是从Web.Release.Config中的工作值中复制的,其中带有“ 替换为“。
我尝试了其他变体:使用“ 保持原样,在末尾附加元数据,但无济于事。 我用第二个网站转载了这个问题。
解决我的问题的方法是,即使数据库确实在SQL Azure上运行,也要从Entity Framework连接字符串的“ SQL Azure / SQL Server / MySQL / Custom”选择器中选择“自定义”而不是“ SQL Azure” 。
[编辑]来自@ matthew-steeples的以下流行评论:
对于其他有相同问题的其他人,我要补充一点的是,有时配置文件中会有
"
而不是"
,并且Azure网站需要将其更改为"
我不仅必须使用双引号(或单引号)代替"
(并为类型选择Custom),但是我还必须确保我的转换配置中有一个虚拟值。 我要替换整个connectionStrings节点,但决定保留该节点并添加以下内容:
<add xdt:Transform="Replace" xdt:Locator="Match(name)" name="FooBarEntities" connectionString="temp" providerName="System.Data.EntityClient" />
没有这个,我得到以下错误:
The connection string 'FooBarEntities' in the application's configuration file does not contain the required providerName attribute.
除了上述答案,还有2个非常重要的事情:
公共MyEntities(string connectionString):base($“ name = {connectionString}”){}
我有同样的问题。 我解决了,在web.config中放入以下连接字符串:
<add name="eManagerTurModelConnection" connectionString="metadata=res://*/ORM.eManagerFinanceModel.csdl|res://*/ORM.eManagerFinanceModel.ssdl|res://*/ORM.eManagerFinanceModel.msl;provider=System.Data.SqlClient;provider connection string="Data Source=<server>.database.windows.net;Initial Catalog=eManagerTur;Integrated Security=False;User ID=<user>;Password=<Password>;Connect Timeout=15;Encrypt=False;TrustServerCertificate=False;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
在删除网站的连接字符串后,它可以正常工作,因为它没有获得我在web.config中添加的连接字符串。
英语不好... =)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.