2015-01-06 58 views
0

无法使用实体框架6.0.0.0无法使用实体框架6.0.0.0

几秒钟前连接到MySQL在ASP.NET MVC连接到MySQL在ASP.NET MVC | LINK

喜,

我已经尝试通宵连接我的ASP.NET MVC项目到MySQL数据库,但我不成功。我发现代码连接到这个链接上的MySQL数据库(使用MVC 4)

在stackoverflow上。不过,我正在使用MVC 5和EF 6来连接,似乎有什么不妥。当访问数据库时,会抛出异常

“System.InvalidOperationException”类型的异常出现在EntityFramework.dll但在用户代码中没有处理 其它信息:没有实体框架提供发现ADO.NET提供程序用不变的名字'MySql.Data.MySqlClient'。确保提供程序在应用程序的'entityFramework'部分中注册

我连接到MySql数据库我已创建并使用web.config文件上的连接字符串。我按照我提供的链接指定了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> 

回答

0

为MySQL提供你名字似乎不正确:

providerName="MySql.Data.MySqlClient" 

你应该找到合适的供应商。我建议从MySQL网站获得官方提供商。他们也有EF 6.0的提供者。

+0

我在web.config中看不到我错误地写了提供程序的名称。请指出,所以我可以改变。唯一的地方我找到providerName我看到我提供了“MySql.Data.MySqlClient”。感谢您的快速响应 – Dev

+0

qamar

+0

我已复制粘贴你提供的代码,但异常仍然抛出。我可以看到来自抛出的Exception的一些信息,它声明**“确保提供程序在应用程序的'entityFramework'部分中注册”**这可能是问题吗? – Dev