Thursday, 15 March 2012

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

You may run into this error when you attempt to reference and consume an Entity Data Model that has been created in a stand-alone project as a class library, from a new 'client' project such as a Windows Forms project, Windows Console App, or an ASP.Net project.

FIX:
The reason for the error is, after you add a reference in the consuming project to the Entity Data Model DLL, you mustn't forget to either:

a) create your own .config file in the consuming project and add the connectionstring entry of the Entity Data Model,
or
b) copy the App.config file from the Entity Data Model project, into the consuming project (by right-clicking the Project > Add Existing Item > Navigating to the Entity Data Model project and selecting its App.config file).

Also worth checking to make sure that the model's MetaData Artifact Processing property is set to 'Embed in Ouput Assembly' which effectively ensures all the required schema files are embedded into the compiled DLL as resources, and are also made a part of the connection string for the model. (In the Entity Data Model project, double-click to open the model and check it’s MetaData Artifact Processing property in the Properties window, by default this should already be set to ‘Embed in Output Assembly’).

1 comment: