Reputation: 3870
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="data source=localhost;initial catalog=MyApplicationEntitiesDB;integrated security=True;multipleactiveresultsets=True;App=EntityFramework""
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.
Upvotes: 53
Views: 67706
Reputation: 4679
If you get this error and you're working with Oracle DBs in .NET, check your existing <connectionStrings>
tag in the startup project (web.config
in web projects, app.config
in console/Windows projects), and make sure Oracle didn't replace it with nonsense.
Installing the Oracle.ManagedDataAccess.*
assemblies from NuGet does this obnoxious thing where it deletes whatever <connectionStrings>
tag that already existed in destination project and replaces it with a new one at the bottom containing a boilerplate Oracle connection string.
Do a git diff
or whatever you use to diff changes and focus on your *.config files. Restore old connection strings as needed, then rebuild and try again.
For all others, just remember that the <connectionStrings>
tag is only read from the startup project's configuration (aka the entry assembly). If you have your DB stuff in another project that is referenced by your startup project, and you have an app.config
in that DB project with a <connectionStrings>
tag in it, that tag is only used for for scaffolding EF stuff. After that, the DB project reads the tag from the startup project's configuration instead of its own.
Upvotes: 0
Reputation: 170
In my case, i got two projects:
I just have to copy the connection string from DAL App.Config project to WPF App.Config project
Upvotes: 0
Reputation: 1129
For anyone arriving here because they are getting this error while working with WPF in Visual Studio, please take a look at this post: Does MVVM stop the ability for the Visual Studio Designer to show xaml?
Upvotes: -1
Reputation: 2408
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.
Upvotes: 1
Reputation: 3870
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
Upvotes: 110
Reputation: 89
Make sure your statup project config file has the connection string.This link may help you.
Upvotes: 8
Reputation: 71
I also had this problem and solved it by
StartUp project
. Things worked out as expected.
Upvotes: 7
Reputation: 2252
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!!
Upvotes: 31
Reputation: 8616
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.
Upvotes: 3
Reputation: 2748
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.
Upvotes: 43