Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to have multiple projects accessing same Entity Framework project?

Ok, this question has been asked many times. Just googling with the error message:

The specified named connection is either not found in the configuration,
not intended to be used with the EntityClient provider, or not valid.

I have tried all suggestions on forums, help sites et blogs... nothing works!

Situation recap

I'm splitting solution into three different projects: one for my model with EF4, one of WinForm and one ASP.NET MVC web application. I have a problem with connections string and configuration.

Is there a updated solution using VS2010/EF4/.NET Framework 4.0?

like image 375
sgy Avatar asked Apr 27 '10 20:04

sgy


2 Answers

Not sure, but you may have to move the Entity Framework configuration sections in your EF4 project's app.config file to both your WinForm app.config and ASP.NET MVC web.config files.

like image 129
Kevin Pang Avatar answered Oct 17 '22 03:10

Kevin Pang


Really, the answer is copying the <connectionStrings> section in the other project's config files like mentionned above.

<connectionStrings>
    <add name="DataEntities" connectionString="metadata=res://*/DataModel.csdl|res://*/DataModel.ssdl|res://*/DataModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=xxx;Initial Catalog=xxx;User Id=xxx;Password=xxx;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient" />
</connectionStrings>

So, it's the same answer as I saw before on many sites. In fact, it was working from the beginning, but I had another error ("Configuration system failed to initialize"), so I thought it was a wrong value of the connection string in the app.config. In fact, the app.config was valid, but just moving the section on bottom solved this... Bizarre?

like image 40
sgy Avatar answered Oct 17 '22 02:10

sgy