Reputation: 1093
I have a second project in my solution called DataAccess (.NET Framework Class Library) for models. I set my main asp .net mvc project as start up and from package manager console I set DataAccess as default. I already have an existing database. So I installed Entity Framework in DataAccess layer using package-install
command to get the latest. Then I added an Entity Data Model. But whenever I try to run enable-migrations
from PM it shows that No connection string named 'MAHMHEntities' could be found in the application config file.
Although there is a connectionString in App.config called MAHMHEntities
. In my MAHMHEntities.cs class I have declared the connection string:
namespace DataAccess.Entities
{
using System.Data.Entity;
public partial class MAHMHEntities : DbContext
{
public MAHMHEntities()
: base("name=MAHMHEntities")
{
}
//other dbset classes
}
}
In DataAccess layer I have App.config file that has two connectionString, I added the DefaultConnection
myself :
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=.\SQL2014;Initial Catalog=MAHMH;Integrated Security=SSPI" providerName="System.Data.SqlClient" />
<add name="MAHMHEntities" connectionString="data source=.\SQL2014;initial catalog=MAHMH;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework" providerName="System.Data.SqlClient" />
</connectionStrings>
Whichever connection I use I always get the same error when I try to enable migration. Entity Framework version is 6.2.0.
Upvotes: 0
Views: 2324
Reputation: 4298
You need to set Data access project as start up project. Or you can add your connection string to web application's(Which is currently start up project) web.config
Upvotes: 4