Blue Theme Orange Theme Green Theme Red Theme
 
Team Foundation Server Hosting
Home | Forums | ASP.NET 2.0 Tutorials | Web Services | How Do I...? | Class Browser | WPF Quick Starts | Advertise with Us
 | Consulting  
Submit an Article Submit a Blog 
Search :       Advanced Search »
Home » Blogs Home » Blog Detail

Metadata Exception in Entity Framework Connection Strings

 by John Penn on Feb 02, 2012

My experience with a cryptic error message encountered during evaluation of Entity Framework 4.0 with SQL Server Compact Edition 4.0.
Comments: 2 Views: 425 Printable Version 
After generating the entity model and classes for my existing SqlCe database, I tried to run some LINQ queries against it.  The following exception was thrown as soon as I tried to instantiate the ObjectContext:

unable to load the specified metadata resource

The metadata that the error message refers to is in the connection string.  This was automatically generated for me, so why would it fail?  After lots of googling, I found this page on Craig Stuntz's blog that has some very handy troubleshooting tips.  He lists several possibilities as to why the metadata would be the cause of the error, but in my case it was the use of the asterisks in the paths in the embedded resources:

metadata=res://*/MyModel.csdl|res://*/MyModel.ssdl|res://*/MyModel.msl

As Craig points out, it is better to replace the asterisks with the explicit name of the assembly that contains the model as in:

metadata=res://MyDAL/MyModel.csdl|res://MyDAL/MyModel.ssdl|res://MyDAL/MyModel.msl

If this doesn't work for you, you may need to use a tool such as Reflector to find the exact path of the resources within the compiled DLL.  In my case, my model was in a sub-directory of the DAL project (named "Client"), so my metadata now looks like this:

metadata=res://MyDAL/Client.MyModel.csdl|res://MyDAL/Client.MyModel.ssdl|res://MyDAL/Client.MyModel.msl

I haven't encountered the metadata exception since I made this change.
Comment Request!
Thank you for reading this post. Please post your feedback, question, or comments about this post Here.
 
What do you say about this post? Post a comment here
*Title:
*Comment:
 

Nice by Mahesh Chand On Feb 02, 2012
Fingers crossed :)

Nice by Mahesh Chand On Feb 02, 2012
Fingers crossed :)

6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor

 Blogger's Profile
Age: Not Available
Location:
Title: Architect
Joined: Oct 10, 2007
Education: Bachelors Degree
 More Blogs from this Blogger
No record available
 Latest Blogs
[Video] OnClose Handler
[Video] Storing and Loading the Window and Toolbar position
The Euclidean Algorithm
Swapping Exe Process
How Exe file is Generated by VS2005 C++ Project?
What is Exe
Header files: Multiple Inclusion problem - Solution B
Header files: Multiple Inclusion problem - Solution A
Header files: Multiple Inclusion problem - Reason
Header files: Multiple Inclusion problem
View all »
 Latest Jobs
More ... 
 Latest Interview Questions
More ... 

 © 2012  contents copyright of their authors. Rest everything copyright Mindcracker. All rights reserved.