The type initializer for 'System.Data.Entity.Internal.AppConfig' threw an exception

前端 未结 26 869
臣服心动
臣服心动 2020-11-30 06:17

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

相关标签:
26条回答
  • 2020-11-30 06:44

    Change this part in your Web.config, according to the below code.(try this, it works to me.)

    <entityFramework>
        <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework">
          <parameters>
            <parameter value="Data Source=.; Integrated Security=True; MultipleActiveResultSets=True" />   
          </parameters>
        </defaultConnectionFactory>
      </entityFramework>
    
    0 讨论(0)
  • 2020-11-30 06:44

    I faced similar issue and changing defaultConnectionFactory to be SqlConnectionFactory helped me solve it.

    0 讨论(0)
  • 2020-11-30 06:45

    Old question but it just happened to me for different reasons mentioned in the other answers, so I thought I'd share my findings.

    In my case, the problem was how I defined my connection string entry in the app.config. I edited it directly in Notepad++ and I must have hit a shortcut, and minimized the entire string which I didn't spot, and started to get this error. This is how I was defined it:

    <add name="MyDb" connectionstring="data source=MyServer;
     initial catalog=MyDatabase;integrated security=true" 
     providername="System.Data.SqlClient" />
    

    The second I changed the following parameters

    connectionstring to connectionString
    

    and

    providername to providerName
    

    Note: The problem was highlighted immediately In Visual Studio but clearly this isn't ideal if you're on a client site!

    0 讨论(0)
  • 2020-11-30 06:46

    I ran into this issue when I forgot to set my Connections.config file to "copy always"

    BareMessage = "Unable to open configSource file 'Connections.config'."

    0 讨论(0)
  • 2020-11-30 06:49

    Check the C-drive inside C:\inetpub\wwwroot and remove all unnecessary folders from it, else remove unnecessary host files or folders from IIS.

    0 讨论(0)
  • 2020-11-30 06:50

    I had multiple providers specified in my web.config.

     <providers>
          <provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6" />
          <provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6, Version=6.9.6.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"></provider>
        </providers>
    

    I simply removed one of those and it worked.

    I am using MySQL though, not TSQL

    0 讨论(0)
提交回复
热议问题