Connection string named "MyApplicationEntities" cannot be found in application configuration file

I just install EF 4.3 and try to upgrade my project using migration. however, I am having problems trying to run add-migration initial in my project using the package manager console.

Now it throws any exception No connection string named 'MyApplicationEntities' could be found in the application config file.

Now my configuration 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 the problem is: is it a bug in EF 4.3 or is there something that I am not doing right.

I thought this post solved the problem, but not quite.

Anyone got a response.

Appreciate Sanj.

+42
database-migration connection-string
Jun 11 2018-12-12T00:
source share
7 answers

Ah, I realized this by accident.

I had to remove

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

to

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

EF 4.3 does not like the connection string to be called name=xxxxx

+95
Jun 11 2018-12-11T00:
source share

The solution indicated in Sanj indicated that you need to copy the connection string from the App.config database project to the web.config web project. I am not sure why the above answer is marked as correct. I am adding this as an answer instead of a comment so that future readers will notice it.

+35
May 6 '13 at 14:50
source share

I had the same error, but I already had the web.config file with the correct connection string name and the DbContext was correctly declared. However, I noticed that when I ran add-migration with -Verbose, it indicated the “Startup Project” as a different project than the one that contains my context. So I change the Startup Project, re-run add-migration and it all works !!

+25
Jan 28 '14 at 19:32
source share

Verify that there is a connection string in the statup project configuration file. This link may help you.

+8
Jun 16 '15 at 6:09
source share

I also had this problem and it was solved with

  • Choosing the right StartUp project .
  • Restarting the command in the package manager console.

Things as expected.

+5
May 18 '15 at 20:50
source share

I also came across a similar exception. Initially, AppConfig is created in the project that we create the entity model. But if you are running the application using some other project (there are several projects in my solution), AppConfig must be included in the project that is running.

+2
Nov 08 '13 at 7:57
source share
  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 the configuration file of a running project.

0
Oct 21 '17 at 13:01
source share



All Articles