EF4 and connection string

I have a three-level project.

1) Project.Data (EDMX file)
2) Project.Model (POCO)
3) Project.Console (console application)

I added a connection string to Project.Console .

 <?xml version="1.0" encoding="utf-8"?> <configuration> <connectionStrings> <add name="ProjectEntities" connectionString="metadata=res://*/Project.csdl|res://*/Project.ssdl|res://*/Project.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=PC\SQLEXPRESS;Initial Catalog=Project;Integrated Security=True;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient" /> </connectionStrings> </configuration> 

Project.Model built using the EntityObject T4 template in VS2010. It generates an ObjectContext class, with this constructor:

 public ProjectEntities() : base("name=ProjectEntities", "ProjectEntities") { this.ContextOptions.LazyLoadingEnabled = true; OnContextCreated(); } 

I am just trying to instantiate a context object in Project.Console :

 namespace Project.Console { class Program { static void Main(string[] args) { ProjectEntities pe = new ProjectEntities(); } } } 

However, I get a MetadataException was unhandled in the constructor. Unable to load the specified metadata resource. statement Unable to load the specified metadata resource.

I did a lot of research (Googling) and found that this is a connection problem with these resources. I can't seem to find a resolution.

Any help is appreciated.

+7
visual-studio-2010 connection-string entity-framework-4
source share
3 answers

I wrote a long guide to debugging this error some time ago.

+8
source share

Open the assembly using any resource viewer (for example, RedGate.NET Reflector) and make sure that the metadata resource name matches the name specified in app.config.

+3
source share

Please replace * with your project.data assembly as shown below

 <add name="ProjectEntities" connectionString="metadata=res://Project.Data/Project.csdl|res://Project.Data/Project.ssdl|res://Project.Data/Project.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=PC\SQLEXPRESS;Initial Catalog=Project;Integrated Security=True;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient" /> 
0
source share

All Articles