2014-09-24 114 views
1

我想部署一个MVC应用程序使用Web部署的EC2实例,并且一切工作,直到我尝试运行该应用程序。我收到以下错误:问题与Web.config

解析器错误消息:为entityFramework创建配置节处理程序时发生错误:在应用程序配置中多次指定DbContext类型'Project.Modules.AppDbContext,Project'的配置。每个上下文只能配置一次。

我已经看了所有我能找到的相关问题(error There is a duplicate 'entityFramework' section definedThere is a duplicate 'entityFramework' section defined - EntityFramework6 upgradeThe type initializer for 'System.Data.Entity.Internal.AppConfig' threw an exceptionThe provider for invariant name System.Data.SqlClient is specified multiple times)。这是一个MVC应用程序,所以有多个Web.config文件,但它抱怨的EF部分在两个地方都不存在。这里是我的配置文件的相关部分:

<configSections> 
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> 
</configSections> 
--------more config settings here--------- 
<entityFramework> 
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework"> 
    <parameters> 
     <parameter value="Data Source=MYIP;Initial Catalog=db;Persist Security Info=True;User ID=user;Password=password" /> 
    </parameters> 
    </defaultConnectionFactory> 
    <providers> 
    <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" /> 
    </providers> 
</entityFramework> 

我听说它的任何东西都应该在6.1.0解决许多其他事情。如果我从configSection中删除条目,它会给我带来另外一个关于如何找不到合适资源的错误。唯一值得注意的其他事情是,如果我部署并取消选中“执行代码优先迁移”,它只是超时而不是给我上述错误。

回答

1

检查web.config在应用虚拟目录的根目录或父目录中。由于web.config继承,发生重复节错误。

wwwroot 
    |-- web.config  <-- ensure this doesn't have any connection strings 
    |-- your app 
     |-- web.config <-- inherites wwwroot\web.config's settings 
0

由于vcsjones在他们的答案here 问题是在你的parent directory。即使你指定的一个,已经有一个在.config file状态。

+0

我认为这是类似于这个......但它看起来像问题是网站/应用程序的关系。我有我的网站'项目',但我也在该网站中创建一个名为'项目'的应用程序,它创建了一个循环关系,我认为这导致了我的很多问题。有一个更好的方法吗? – awh112 2014-09-24 15:11:25

+0

这不就是我说的吗? – Mrchief 2014-09-24 19:23:31