实体框架代码优先 Azure 连接
我正在使用 Entity Framework Code First 4.3 + Azure,但在连接到数据库时遇到困难。我得到的错误如下(在第一个查询中):
Keyword not supported: 'server'.
我在 Web.config 中设置了以下连接
<configSections>
type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.3.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</configSections>
<connectionStrings>
<add name="TestDBContext"
connectionString="Server=tcp:[SUBSCR].database.windows.net,1433;Database=[MyDB];User ID=[user];Password=[pass];Trusted_Connection=False;Encrypt=True;PersistSecurityInfo=True"
providerName="System.Data.EntityClient" />
</connectionStrings>
我的 DbContext 实现类使用连接字符串的名称:
public class MyContext : DbContext, IMyContext
{
public MyContext()
: base("TestDBContext")
{
Configuration.LazyLoadingEnabled = true;
Configuration.ProxyCreationEnabled = true;
}
你能告诉我发生了什么吗?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
我刚刚遇到了同样的问题。
您缺少实体框架所需的连接字符串中的所有元数据。 SQL Azure 提供的连接字符串需要插入到 EF 连接字符串的
provider connection string
参数中。您需要使用您自己项目中的元数据。我从现有数据库生成的 EF 项目中提取了该元数据。
I just had the same problem.
You're missing all the metadata in the connection string that Entity Framework requires. The connection string provided by SQL Azure needs to inserted within the
provider connection string
parameter of EF's connection string.<add name="MyConnectionString" connectionString="metadata=res://*/Model.Model.csdl|res://*/Model.Model.ssdl|res://*/Model.Model.msl;provider=System.Data.SqlClient;provider connection string="[PUT SQL AZURE CONN STRING HERE]"" providerName="System.Data.EntityClient" />
You'll need to use the metadata from your own project. I pulled that metadata from an EF project generating from an existing database.
我也有同样的问题。我解决了,将这个连接字符串放入 web.config 中:
在删除网站的连接字符串后,工作正常,因为它没有获取我在 web.config 中添加的连接字符串。
英语不好... =)
I had the same problem. I solved, putting in the web.config this connectionstring:
And after I removed the connectionstring of my website, worked, because it was not getting the connection string that I added in my web.config.
English bad... =)
提供程序应该是providerName =“System.Data.SqlClient”
我从VS连接到Azure,然后查看属性并设置我的连接字符串和提供程序名称。
然后我就可以毫无问题地运行更新数据库。
The provider should be providerName="System.Data.SqlClient"
I connected to Azure from VS and then looked at the properties and set my connection string and provider name.
I was then able to run update-database with no issues.
我尝试过这样,它可能对你有帮助。可能是1433有问题,是端口号吗?或者什么? 。尝试这样。
检查此链接 Windows Azure with Sql< /a>
i tried like this, it may help you. may be 1433 is making problem, is it port no ? or what? . try like this.
check this link Windows Azure with Sql
试试这个:
还有一篇 MSDN 文章 http://msdn.microsoft.com/ en-us/library/windowsazure/ff951633.aspx 这可能会有所帮助。
Try this:
There is also an MSDN article at http://msdn.microsoft.com/en-us/library/windowsazure/ff951633.aspx that may be helpful.
我遇到了类似的问题,我无法访问元数据,在这种情况下,您需要使用 System.Data.SqlClient 作为提供程序。您还需要将 MultipleActiveResultSets=True 添加到连接字符串中
I had a similar problem where I did not have access to the metadata, in this case you need to use System.Data.SqlClient as the provider. You will also need to add MultipleActiveResultSets=True to your connection string