I\'m working with EF5 in a MVC 4 aspnet website. Locally, everything works just fine, but when I publish it to the IIS and try to enter, I get the error
I had the duplicit definition of connection string in my WCF service. I was able to debug the service and to see the inner error message (not displayed by default):
ConfigurationErrorsException: The entry 'xxxEntities' has
already been added. (C:\Users\WcfService\web.config line 35).
which was after web.config transformation (note duplicit values)
<connectionStrings>
<add name="xxxEntities" connectionString="metadata=res://*/ ...
<add name="xxxEntities" connectionString="metadata=res://*/ ...
Hence removing unwanted connection string solved my problem.
I think the problem is from this line:
<context type="GdpSoftware.Server.Data.GdpSoftwareDbContext, GdpSoftware.Server.Data" disableDatabaseInitialization="true">
I don't know why you are using this approach and how it works...
Maybe it's better to try to get it out from web.config and go another way
I had this error today on a nested MVC application running as virtual folder in onother MVC application. In my case the InnerException was more informative than the main one. It was stating:
- The entry 'DbContextMain' has already been added. (C:\inetpub\...\web.config line x)
After fixing the duplicate connection strings in the nested apps everything worked fine.
I also faced the same issue, however in my case my solution has a console application and EF class library which mainly interacts with database. I removed Config settings related to EF from the Console Application Config. I maintained the following configuration settings in EF class library i.e only at one place.
This worked for me.
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.2.61023.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<add name="EntityModel" connectionString="Server=Localhost\SQLEXPRESS;Database=SampleEntities;Trusted_Connection=True;" providerName="System.Data.EntityClient" />
Search in your web.config
or App.Config
if you have some tags that are not used in your project or you don't have in your references.
In connection string, the first string is the base in web.config
SchedulingContext is the base parameter of Entity file.
<connectionStrings>
<add name="SchedulingContext" connectionString="Data Source=XXX\SQL2008R2DEV;Initial Catalog=YYY;Persist Security Info=True;User ID=sa;Password=XXX" providerName="System.Data.SqlClient"/>