Windows Azure, Entity Framework. Keyword not supported: 'metadata'.

人走茶凉 提交于 2019-12-01 04:18:46

Here is my connection string defined in the Azure portal, for a DatabaseFirst approach :

metadata=res://*/mySuperModel.csdl|res://*/mySuperModelModel.ssdl|res://*/mySuperModel.msl;provider=System.Data.SqlClient;provider connection string="Data Source=tcp:myServerName.database.windows.net,1433;Initial Catalog=myDatabaseName;User ID=myUserName@myServerName;Password=myPasswordHere;"

Compare with yours and note that the connection type is "custom" in the azure portal.

I had the same problem as the OP, but his solution didn't work for me.

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)). I'm using database first to create my .edmx file (I generate the (data) model from the database)] is:

<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. 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.)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!