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

If you get the error above in your web browser it might be due to Visual studio 2010 not updating the web.config file.

—-

Creating an Entity framework 2 multi tier (n-tier/ntier) aspnet mvc 2 solution in Visual studio 2010 wasn’t the next-next-next or just-follow-an-example I first thought.

The first try rendered a “The specified named connection is either not found in the configuration, not intended to be used with the EntityClient provider, or not valid.” message in the browser.  There were mainly two answers through google:
1) create a Mydatalayer.dll.config and insert the connection string there
2) update the web.config and insert the connection string there

I tried them both to no avail. I knew my connection string was correct because I could use it through a test dll.

Finally I found out that the web.config file in the web project does not get copied to the output.  It fooled me since I saw that there were 3 web config files (ordinary+debug+release) in the site.

Now I don’t dare to set the web.config in VS2010 to Copy-if-newer since the web.config already in the site has almost 80 rows already and I don’t want to overwrite it.

Updating the web.config in the site will save me for now.  I will figure out how to do it the right way later.

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

  1. Anonymous says:

    using ef4 give the connectionstring in the constructor of the datacontext also works

  2. selfelected says:

    I am the OP and I can’t understand what I wrote above. Maybe if I dig up that project.
    Nevertheless I stumbled on the same exception again. I had updated my web.config but and the web.config doesn’t have to be copied – it is in the right place from the start. But it was the wrong web.config. It is an aspnetmvc3rc1 project and there is a web.config under /Views and one in root. Update root – not /Views…

  3. Manuel says:

    It might be a late reply, but the problem is that the referencing project is not aware of the connection name and thus unable to start the instance of the EF repository class.
    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);

  4. admin says:

    @Manuel: ROCK!

  5. The solution is obvious when you think about it.. the error just makes it look like a big fault.
    My Entity Object was in a different project and I needed to copy the Connection String from it’s App.Config to my Web.Config.

Leave a Reply