2014-09-24 80 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