gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 23:16:09 26 4
gpt4 key购买 nike

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

几秒钟前|LINK

嗨,

我整夜尝试将 ASP.NET MVC 项目连接到 MySQL 数据库,但没有成功。我在此链接上找到了连接到 MySQL 数据库(使用 MVC 4)的代码

在 stackoverflow 上。但是我使用 MVC 5 和 EF 6 进行连接,似乎有些问题。访问数据库时抛出异常

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

我连接到了我创建的 MySql 数据库,并使用了 web.config 文件中的连接字符串。我按照我提供的链接指定的方式设置了 web.config。不过,我没有设置简单成员(member)资格,因为我目前不需要它。 我能够在同一 MySQL 数据库上使用 EF 创建具有读写操作的 Controller ,没有任何问题。我已将整个 web.config(项目根目录下的 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 网站获取官方提供商。他们也有 EF 6.0 的提供程序。

关于mysql - 无法使用 Entity Framework 6.0.0.0 在 ASP.NET MVC 中连接到 MySQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27791817/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com