Entity Framework DbContext Connection string not seen in app.config/web.config

database-first dbcontext ef-code-first entity-framework


Therefore, I tried to create a tiny test project by following this advice from the ADO.NET team blog. Every detail has been examined twice. It seems to be broken and constantly reporting that a connection string is missing.


Build this UserModels.dll in Step 1. This connection string was produced by edmx and stored in the dll, App.Config file: (after creating it, click the "test" button, and it connected successfully and produced an edmx diagram of all the tables from the "UserDatabase").

<?xml version="1.0" encoding="utf-8"?>
    <add name="UserModelsContainer" connectionString="metadata=res://*/UserModels.csdl|res://*/UserModels.ssdl|res://*/UserModels.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=MyDesktop\SQL2008;initial catalog=UserDatabase;integrated security=True;multipleactiveresultsets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />

Next, I created a test project:

class UnitTetst1 ....
using (var db = new UserModelsContainer()) {
  int i = db.Users.Count(); // <---expecting '0' for a new db, but I get an exception

————- ISSUE HERE ————————-

3. Conduct the test. I then get the following InvalidOperationException error:

"No connection string named 'UserModelsContainer' could be found in the application config file."

It seems that DbContext is unsure about where to find the connectionStrings in App.Config.

Please assist

5/22/2013 3:36:54 AM

Accepted Answer

5/27/2012 6:36:38 AM

Popular Answer

This problem occurred when I tried to run the update-database command from the "package manager console." I have several projects for my web project, my code-first Data access layer, etc.

I was executing the instruction Update the database by typing "update-database -projectname MYPROJECTDANAME -connectionstringname CONNECTIONSTRING -Force".

As a result, it pointed to my MYPROJECTDANAME project, but it uses the startup project you gave to get the connectionstring name. As a result, confirm that the project you have selected as the starter project has the necessary connection string.

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow