简体   繁体   English

实体框架迁移无法在App.config文件中找到连接字符串

[英]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.

相关问题 在app.config中找不到实体框架连接字符串 - Can't Find Entity Framework Connection String in app.config App.Config中的实体框架连接字符串 - Entity Framework Connection String in App.Config 实体框架未在app.config中使用连接字符串 - Entity Framework not using connection string in app.config 在Entity Framework的app.config中更改连接字符串 - Changing connection string in app.config for Entity Framework app.config和用于远程连接的实体框架 - app.config and Entity Framework for remote connection 未创建实体框架 6 App.config 文件 - Entity Framework 6 App.config file is not created 当连接字符串在自定义配置文件中时,实体框架迁移失败 - Entity Framework Migration fails when connection string is in custom config file 实体框架(代码优先到现有数据库)-在运行时覆盖app.config中的连接字符串 - Entity Framework(Code First to an existing database) - overwrite a connection string in app.config at runtime 强制实体框架和ASP.MVC使用另一个程序集的app.config中的连接字符串 - Forcing Entity Framework and ASP.MVC to use the connection string from app.config of another assembly 实体框架抛出无效操作异常 - 找不到app.config中的连接字符串 - Entity framework throwing invalid operation exception - Connection string in app.config not found
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM