简体   繁体   English

实体框架4.3 Windows Azure关键字不受支持:“元数据”

[英]Entity Framework 4.3 Windows Azure Keyword not supported: 'metadata'

My Code works locally, with connection string pointing to AZURE SQL SERVER. 我的代码在本地工作,连接字符串指向AZURE SQL SERVER。 But as soon as i publish to Azure Web Site every View with EF Model throws this error. 但是,一旦我发布到Azure网站,带有EF模型的每个视图都会引发此错误。 I have change the " to ' as one of the proposed solutions, nothing works. Im stuck!! 我已将“”更改为建议的解决方案之一,但没有任何效果。

  System.Data.EntityException: The underlying provider failed on ConnectionString. ---> System.ArgumentException: Keyword not supported: 'metadata'.
   at System.Data.Common.DbConnectionOptions.ParseInternal(Hashtable parsetable, String connectionString, Boolean buildChain, Hashtable synonyms, Boolean firstKey)
   at System.Data.Common.DbConnectionOptions..ctor(String connectionString, Hashtable synonyms, Boolean useOdbcRules)
   at System.Data.SqlClient.SqlConnectionString..ctor(String connectionString)
   at System.Data.SqlClient.SqlConnectionFactory.CreateConnectionOptions(String connectionString, DbConnectionOptions previous)

If you have MultipleActiveResultSets=True in your connection string then please remove it and the same connection string should work in Windows Azure. 如果您的连接字符串中包含MultipleActiveResultSets = True ,请删除它,并且相同的连接字符串在Windows Azure中应该可以使用。 I found this being most common error in your situation. 我发现这是您情况中最常见的错误。

If that is not the case, please post your connection string and I will take a look. 如果不是这种情况,请发布您的连接字符串,我会看一下。

I had the same problem as the OP, but his solution didn't work for me. 我遇到了与OP相同的问题,但是他的解决方案对我不起作用。

It was a connection string issue, but not with the quotes. 这是一个连接字符串问题,但不是引号。

Since it took me two days to resolve, maybe this will help someone else: 由于花了我两天时间解决,也许这会对其他人有所帮助:

The connection string that works [for my ASP.NET MVC 4.5/Entity Framework 5.0 application when hosted on Azure (I develop against SQL Server 2012 locally, but migrate the database to Azure SQL Database (using the SQL Database Migration Wizard )). [当托管在Azure上时 ,适用于我的ASP.NET MVC 4.5 / Entity Framework 5.0应用程序的连接字符串(我在本地针对SQL Server 2012开发,但是将数据库迁移到Azure SQL数据库(使用SQL数据库迁移向导 ))。 I'm using database first to create my .edmx file (I generate the (data) model from the database)] is: 我首先使用数据库来创建我的.edmx文件(我从数据库中生成(数据)模型)]是:

<add name="MYPROJECTENTITIES" connectionString="**metadata=**res://*/MODELS.MYPROJECTMODEL.csdl|res://*/MODELS.MYPROJECTMODEL.ssdl|res://*/MODELS.MYPROJECTMODEL.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=tcp:B6JD5K5EP4.database.windows.net,1433;Initial Catalog=MYPROJECT_DB;Integrated Security=False;User ID=MYPROJECT@B6JD5K5EP4;Password=MYPASSWORDABC123;**MultipleActiveResultSets=True**;Encrypt=True;TrustServerCertificate=False&quot;" providerName="System.Data.EntityClient"/>

The text in UPPERCASE is my Azure information. 大写中的文字是我的Azure信息。 Obviously, you'll need to use your own instead. 显然,您需要使用自己的。

This part of the connection string gave me nightmares, and it could be causing your issue as well: 连接字符串的这一部分给了我噩梦,它也可能导致您的问题:

res://*/Models.MyProjectModel.csdl|res://*/Models.MyProjectModel.ssdl|res://*/Models.MyProjectModel.msl

Those references have to be exactly right . 这些参考必须完全正确 Let me repeat: Those references have to be exactly right!! 让我重复一遍: 这些引用必须完全正确!

After reading this article from 2008 ("Troubleshooting Entity Framework Connection Strings"), I used .NET Reflector to look inside the MyProjectModel.dll (the name of my .dll (likely different in your project) like he suggests and, sure enough, the connection string (that was generated automatically for me by the Entity Framework!) was wrong. It didn't include a prefix. As soon as I added Models. prefix (which is how the .csdl/.msl/.ssdl are named inside of my .dll (likely different in yours)), everything worked great. Have a look inside your .dll and see if the names match. If not, change them to match what appears in the .dll. (Read the article above if what I'm saying isn't clear enough.) 在阅读了2008年的这篇文章 (“对实体框架连接字符串进行故障排除”)之后,我使用.NET Reflector像他建议的那样在MyProjectModel.dll(我的.dll的名称(在您的项目中可能有所不同)的内部)中查找,当然,连接字符串(由Entity Framework自动为我生成的!)是错误的。它不包含前缀。我添加Models。前缀(即.csdl / .msl / .ssdl的命名方式)在我的.dll(可能与您的文件不同)中,一切正常。查看您的.dll并查看名称是否匹配。如果不匹配,请更改它们以匹配.dll中显示的内容。(请阅读上面的文章如果我说的话不够清楚。)

I had to change the connection string type to Custom in Azure portal. 我必须在Azure门户中将连接字符串类型更改为“自定义”。

在此处输入图片说明

Here is my answer on another SO thread that might be helpful. 这是我在另一个SO线程上可能有用的答案。 Steps I have mentioned there include an end-to-end configuration of connection string on Azure and dynamically using it. 我在上面提到的步骤包括在Azure上动态地使用连接字符串的端到端配置。 And yes, it fixes the error in question! 是的,它可以解决相关错误!

https://stackoverflow.com/a/37938912/3785895 https://stackoverflow.com/a/37938912/3785895

More Info: Along with changing the providerName, there are a few extra bits we might need to check. 更多信息:除了更改providerName之外,我们可能还需要检查一些额外的信息。 Azure seems to be updating the web.config file after publishing the API App/Web App. 发布API应用程序/ Web应用程序后,Azure似乎正在更新web.config文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM