No connection string named 'MyApplicationEntities' could be found in the application config file

Connection StringDatabase MigrationEntity Framework-4.3

Connection String Problem Overview


I just install EF 4.3 and trying to upgrade my project with migration. however I am getting issues with trying to execute add-migration initial to my project via Package Manager console.

It is throwing any exception now No connection string named 'MyApplicationEntities' could be found in the application config file.

Now my config has it all

<connectionStrings>
<add name="MyApplicationEntities" 
     connectionString="metadata=res://*/DataModel.csdl|res://*/DataModel.ssdl|res://*/DataModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=localhost;initial catalog=MyApplicationEntitiesDB;integrated security=True;multipleactiveresultsets=True;App=EntityFramework&quot;" 
     providerName="System.Data.EntityClient" />

I am not sure what is the issue is it a bug in EF 4.3 or there is something I am not doing right.

I thought this post has solved the issue but not quite.

Anyone got an answer.

Appreciate Sanj.

Connection String Solutions


Solution 1 - Connection String

Ah, figured this out accidentally.

I had to remove

public MasterEntities()
    : base("name=MyApplicationEntities")
    //      ^^^^^
{
}

to

public MasterEntities()
    : base("MyApplicationEntities")
{
}

EF 4.3 does not like connection string being called name=xxxxx

Solution 2 - Connection String

The solution as Sanj pointed out is that you need to copy the connection string from your database project's App.config to the web project's web.config. I'm not sure why the above answer is marked as correct. I'm adding this as an answer instead of a comment so future readers will spot this.

Solution 3 - Connection String

I had the same error but I already had a web.config file with the correct connection string name and a DbContext declared correctly. However, I noticed when I ran add-migration with -Verbose it state the 'Startup Project' as a different project than the one containing my context. So I change the Startup Project, re-ran the add-migration and it all worked!!

Solution 4 - Connection String

Make sure your statup project config file has the connection string.This link may help you.

Solution 5 - Connection String

I also had this problem and solved it by

  1. Selecting the correct StartUp project.
  2. Rerunning the command on Package Manager Console.

Things worked out as expected.

Solution 6 - Connection String

I also encountered the similar exception. AppConfig is originally gets created in the project that we generate the entity model. But if you are executing the application using some other project (there are several Projects in my solution), the AppConfig needs to be included in the project which is being executed.

Solution 7 - Connection String

 1. ctor => Context

   public MasterEntities()
    : base("ConnectionStringName")
{
}

 2. config file

   <add name="ConnectionStringName"
      connectionString="Data Source=.;Initial Catalog=DatabaseName;User Id=sa; Password=YourPass;"
      providerName ="System.Data.SqlClient" />

 3. in Sulation Exporer right click the project and select 'Set as
    startup project'

 4. in PackageManagerConsole Change Default Project to Your Project of
    context class.

 5. then:

add-migration new

> or added ConnectionString to config file of working Project.

Solution 8 - Connection String

In my case, i got two projects:

enter image description here

I just have to copy the connection string from DAL App.Config project to WPF App.Config project

Solution 9 - Connection String

For anyone arriving here because they are getting this error while working with WPF in Visual Studio, please take a look at this post: https://stackoverflow.com/questions/43640361/does-mvvm-stop-the-ability-for-the-visual-studio-designer-to-show-xaml/43642741#comment91374664_43642741

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSanjView Question on Stackoverflow
Solution 1 - Connection StringSanjView Answer on Stackoverflow
Solution 2 - Connection StringBillView Answer on Stackoverflow
Solution 3 - Connection StringPhilView Answer on Stackoverflow
Solution 4 - Connection StringSantosh PanigrahyView Answer on Stackoverflow
Solution 5 - Connection StringxibabababaView Answer on Stackoverflow
Solution 6 - Connection StringDhanuka777View Answer on Stackoverflow
Solution 7 - Connection StringMohammadSooriView Answer on Stackoverflow
Solution 8 - Connection StringRenan DuarteView Answer on Stackoverflow
Solution 9 - Connection StringTelosView Answer on Stackoverflow