无法使用Entity Framework 6.0.0.0在ASP.NET MVC中连接到MySQL

无法使用Entity Framework 6.0.0.0在ASP.NET MVC中连接到MySQL,mysql,asp.net,asp.net-mvc,entity-framework-6,c#-5.0,Mysql,Asp.net,Asp.net Mvc,Entity Framework 6,C# 5.0,无法使用Entity Framework 6.0.0.0在ASP.NET MVC中连接到MySQL 几秒钟前| LINK 嗨 我通宵试图将我的ASP.NETMVC项目连接到MySQL数据库,但没有成功。我在这个链接上找到了使用MVC4连接MySQL数据库的代码 在堆栈溢出上。然而,我使用MVC5和EF6来连接,似乎有点不对劲。访问数据库时,会引发异常 EntityFramework.dll中发生“System.InvalidOperationException”类型的异常,但未在用户代码中处理

无法使用Entity Framework 6.0.0.0在ASP.NET MVC中连接到MySQL

几秒钟前| LINK

我通宵试图将我的ASP.NETMVC项目连接到MySQL数据库,但没有成功。我在这个链接上找到了使用MVC4连接MySQL数据库的代码

在堆栈溢出上。然而,我使用MVC5和EF6来连接,似乎有点不对劲。访问数据库时,会引发异常

EntityFramework.dll中发生“System.InvalidOperationException”类型的异常,但未在用户代码中处理 其他信息:未找到具有固定名称“MySql.Data.MySqlClient”的ADO.NET提供程序的实体框架提供程序。确保提供程序已在应用程序的“entityFramework”部分注册

我连接到我创建的MySql数据库,并使用web.config文件中的connectionstring。我按照我提供的链接设置了web.config。但是我没有建立简单的会员资格,因为我现在不需要它。我能够在同一个MySQL数据库上使用EF创建具有读写操作的控制器,没有任何问题。我已经在我的整个web.config下面包含了项目根目录下的一个

        <?xml version="1.0" encoding="utf-8"?>
    <!--
      For more information on how to configure your ASP.NET application, please visit
      http://go.microsoft.com/fwlink/?LinkId=301880
      -->
    <configuration>
      <configSections>
        <!-- For more information on Entity Framework configuration,                       visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    <!--<section name="entityFranework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />-->
  </configSections>
  <!--<connectionStrings>
    <add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=&quot;|DataDirectory|\aspnet-Automation Of Services-20150105091844.mdf&quot;;Initial Catalog=&quot;aspnet-Automation Of Services-20150105091844&quot;;Integrated Security=True" providerName="System.Data.SqlClient" />
  </connectionStrings>-->
    <connectionStrings>
    <add name="ChangeRequestsContext" connectionString="server=localhost;user id=root;persistsecurityinfo=True;database=changerequests" providerName="MySql.Data.MySqlClient" />
  </connectionStrings>
  <appSettings>
    <add key="webpages:Version" value="3.0.0.0" />
    <add key="webpages:Enabled" value="false" />
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
   </appSettings>
   <system.web>
    <authentication mode="None" />
     <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" />
    </system.web>
    <system.webServer>
      <modules>
        <remove name="FormsAuthentication" />
     </modules>
  </system.webServer>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Owin.Security.OAuth" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
        </dependentAssembly>
        <dependentAssembly>
        <assemblyIdentity name="Microsoft.Owin.Security.Cookies" publicKeyToken="31bf3856ad364e35" />
       <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
       </dependentAssembly>
        <dependentAssembly>
        <assemblyIdentity name="Microsoft.Owin.Security" publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed" />
        <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-5.2.2.0" newVersion="5.2.2.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" />
      </dependentAssembly>
    </assemblyBinding>
   </runtime>
  <!--<configSections>
 <section name="entityFranework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />    
  </configSections>-->
  <entityFramework>
    <!--<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
         <parameters>
            <parameter value="mssqllocaldb" />
           </parameters>
             </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    <provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6, Version=6.9.5.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d">
        </provider></providers>-->
        <contexts>
        <context type="Automation_Of_Services.Models.ChangeRequestsContext, AutomationOfServices">
        <databaseInitializer type="Automation_Of_Services.EntityFramework.MySql.DropCreateMySqlDatabaseIfModelChanges,  AutomationOfServices">
       </databaseInitializer>
      </context>
    </contexts>
    <defaultConnectionFactory type="MySql.Data.MySqlClient.MySqlClientFactory,MySql.Data" />
  </entityFramework>
  <system.data>
    <DbProviderFactories>
      <remove invariant="MySql.Data.MySqlClient" />
      <add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.9.5.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
    </DbProviderFactories>
    <!--<DbProviderFactories>
    <remove invariant="MySql.Data.MySqlClient" />
    <add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient"
         description=".Net Framework Data Provider for MySQL"
        type="MySql.Data.MySqlClient.MySqlClientFactory,MySql.Data" />
     </DbProviderFactories>-->
    </system.data>
   </configuration>

您的mysql提供程序名称似乎不正确:

providerName="MySql.Data.MySqlClient"

您应该找到正确的提供者。我建议从mysql网站获得官方提供商。他们也有EF6.0的提供商

在我的web.config上,我看不到我错误地写入了提供者的名称。请指出,这样我可以改变。在我找到providerName的唯一地方,我提供了MySql.Data.MySqlClient。感谢您的快速响应。我已经复制粘贴了您提供的代码,但仍然会引发异常。我可以从抛出的异常中看到一些信息,这些信息表明确保提供程序已在应用程序的“entityFramework”部分注册。这可能是问题所在吗?不。您需要使用entityFramework的正确Mysql提供程序更新以下内容。providerName=MySql.Data.MySqlClient。您的提供商名称不正确。您需要有用于.net的mysql连接器。这里是你可以下载的地方:一旦你下载了,然后使用这个连接器的dll连接到数据库。我已经下载并安装了最新的连接器。很抱歉,我还不明白你的意思。在安装了最新的连接器后再次抛出异常后,我更改了web.config,这样我找到的每个实例MySql.Data都会添加文本,以便所有实例都读取MySql.Data.MySqlClient。现在我有了一个新的ConfigurationException。详细信息是System.Data.dll中发生的“System.Configuration.ConfigurationErrorsException”类型的异常,但未在用户代码中处理。其他信息:未能找到或加载已注册的.Net Framework数据提供程序。