[英]Entity Framework Migration cant find connection string in App.config file
I have a second project in my solution called DataAccess (.NET Framework Class Library) for models. 我的解决方案中有第二个项目称为模型的DataAccess(.NET Framework类库)。 I set my main asp .net mvc project as start up and from package manager console I set DataAccess as default. 我将主asp .net mvc项目设置为启动,并从包管理器控制台中将DataAccess设置为默认值。 I already have an existing database. 我已经有一个现有的数据库。 So I installed Entity Framework in DataAccess layer using package-install
command to get the latest. 因此,我使用package-install
命令在DataAccess层中安装了Entity Framework,以获取最新版本。 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.
但是,每当我尝试从PM运行enable-migrations
,它都表明No connection string named 'MAHMHEntities' could be found in the application config file.
Although there is a connectionString in App.config called MAHMHEntities
. 尽管App.config中有一个名为MAHMHEntities
。 In my MAHMHEntities.cs class I have declared the connection string: 在我的MAHMHEntities.cs类中,我声明了连接字符串:
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 : 在DataAccess层中,我有具有两个connectionString的App.config文件,我自己添加了DefaultConnection
:
<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. 实体框架版本为6.2.0。
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 或者,您可以将连接字符串添加到Web应用程序的(当前正在启动项目的)web.config中
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.