Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

This has been asked a few times but I haven't been able to make any of the suggestions work for me.

I have a website and SQL database that I've build locally and now deployed into Azure. The database is a linked resource to the website. I am able to browse the website and I'm even able to connect and run queries against the database using ADO.Net and a standard connection string.

The problem is when I try to connect using Entity Framework I keep getting Keyword not supported: 'metadata'. I've removed the multiple active record sets and tried replacing " with ' but it hasn't work. I'm completely stuck for ideas.

like image 974
Jason Murray Avatar asked Dec 17 '12 04:12

Jason Murray


2 Answers

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.

like image 127
JYL Avatar answered Oct 22 '22 02:10

JYL


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

like image 2
Thomas Avatar answered Oct 22 '22 01:10

Thomas