Thursday, September 27, 2012

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


Today I got another problem:

I added Entity Framework 4 (edmx) model in one class library project in .Net 4 and refrenced this project in another Windows Forms project to test the model. I got the following error while reading from database:

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

Solution:

Then I searched it through the internet and I found the following solution:


Assuming there are 2 projects: One that holds the EntityFramework classes (repository) and another project that is an Application project (application) that references the entity framework one. Add a reference to System.Data.Entity to the application project and copy paste the ConnectionStrings block in App.Config from the repository project into the application project:
Other option is to pass the connection string as a parameter while instantiating the classes repository:

MyPortalEntities myPortalEntities = new MyPortalEntities(connnectionString);

No comments:

Post a Comment

Popular Posts