views:

5938

answers:

5

I am using multiple layer project where the DataModel hosts the ADo.NET Entity model and DataAccess layer does the validation.

However everytime I get a error like this

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 connection strings

<add name="SalesEntities" connectionString="metadata=res://*/SalesEntities.csdl|res://*/SalesEntities.ssdl|res://*/SalesEntities.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=.;Initial Catalog=Phoenix;Integrated Security=True;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient" />

and

<add name="SalesEntities" connectionString="metadata=.\SalesEntities.csdl|.\SalesEntities.ssdl|.\SalesEntities.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=.;Initial Catalog=Phoenix;Integrated Security=True;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient" />

also tried other combinations to refer the Root Directory of the Called project directory but no luck.

Any help is highly appreciated. Many Thanks as always :).

+8  A: 

You have to put those connection strings in each applications app.config file. If you have a DAL that you generated the model in, and then try to consume the DAL in an EXE the same thing will happen. The EXE does not know the connection string.

The easiest thing I have found is to put an app.config on each project and just copy the connection string from the DAL I generated the models in originally. Then each will have a copy of that same connection string.

Jason Short
hm, is it somehow possible to store all connection strings in one place and then 'tell' to all web.config files where to find that connection strings?
Tony
You can put them in the MACHINE.CONFIG (global on the machine), but this requires more privs and deployment is not a good idea in that scenario.
Jason Short
A: 

Hi,

I add the same problem, trying to unit-test my DAL. I've found that this works :

<add name="SalesEntities" connectionString="metadata=res://*;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=.;Initial Catalog=Phoenix;Integrated Security=True;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient" /> 
D.Thouvenin
A: 

I had a similar problem with a WinForms project and despite trying everything I could find related to it on the web could not resolve my problem..... until I removed the field that I was using for my ObjectContext (private CubEntities _oc = new CubEntities()) from my BaseForm to the actual form using it.

daveywc
A: 

If you copy your App.Config file into the main project and replace all the &quot; with the normal ' character it should run

keith
A: 

Thanks for the advice. Adding an App.config file with copied connection strings to my 'calling' project fixed the problem for me too.

FCB
I'm having this problem too. So much for the whole "separation of concerns" aspect of MVVM. If I have to have a connection sting in my consuming layer that it copied from my DA layer, it kind of ruins the "separation" part. Lame, but if it works, it works, I guess.
JohnMetta

related questions