C# 无法使用 MySql + MVC4 找到或加载已注册的 .Net Framework 数据提供程序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18657460/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Failed to find or load the registered .Net Framework Data Provider with MySql + MVC4
提问by Wizer
We are getting the following error when we tried running our MVC4 Project with Azure Mysql DB.
当我们尝试使用 Azure Mysql DB 运行我们的 MVC4 项目时,我们收到以下错误。
In Web.Config file we have the following,
在 Web.Config 文件中,我们有以下内容,
<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>
Error:
错误:
Failed to find or load the registered .Net Framework Data Provider.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Configuration.ConfigurationErrorsException: Failed to find or load the registered .Net Framework Data Provider.
无法找到或加载已注册的 .Net Framework 数据提供程序。
说明:在执行当前 Web 请求期间发生未处理的异常。请查看堆栈跟踪以获取有关错误及其在代码中的来源的更多信息。
异常详细信息:System.Configuration.ConfigurationErrorsException:无法找到或加载已注册的 .Net Framework 数据提供程序。
Source Error:
源错误:
Line 96: if (objectQuery != null && !string.IsNullOrEmpty(path))
Line 97: {
Line 98: return objectQuery.Include(path);
Line 99: }
Line 100:
Source File: C:\Phase2\FreeLance\FreeLance\Framework\Data\FreeLance.Data.Framework\EntityFramework\Extensions.cs Line: 98
Stack Trace:
[ConfigurationErrorsException: Failed to find or load the registered .Net Framework Data Provider.]
System.Data.Common.DbProviderFactories.GetFactory(DataRow providerRow) +2238858
System.Data.EntityClient.EntityConnection.GetFactory(String providerString) +143
System.Data.EntityClient.EntityConnection.ChangeConnectionString(String newConnectionString) +641
System.Data.Entity.Internal.LazyInternalConnection.TryInitializeFromAppConfig(String name, AppConfig config) +144
System.Data.Entity.Internal.LazyInternalConnection.Initialize() +95
System.Data.Entity.Internal.LazyInternalConnection.CreateObjectContextFromConnectionModel() +16
System.Data.Entity.Internal.LazyInternalContext.InitializeContext() +269
System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType) +26
System.Data.Entity.Internal.Linq.InternalSet`1.Initialize() +71
System.Data.Entity.Internal.Linq.InternalSet`1.Include(String path) +25
System.Data.Entity.Infrastructure.DbQuery`1.Include(String path) +111
FreeLance.Data.Framework.EntityFramework.Extensions.Include(IQueryable`1 source, String path) in C:\Phase2\FreeLance\FreeLance\Framework\Data\FreeLance.Data.Framework\EntityFramework\Extensions.cs:98
FreeLance.Data.Framework.EntityFramework.Extensions.Include(IQueryable`1 source, Expression`1 expression) in C:\Phase2\FreeLance\FreeLance\Framework\Data\FreeLance.Data.Framework\EntityFramework\Extensions.cs:64
FreeLance.Data.Framework.EntityFramework.Extensions.Include(IQueryable`1 source, Expression`1[] expressions) in C:\Phase2\FreeLance\FreeLance\Framework\Data\FreeLance.Data.Framework\EntityFramework\Extensions.cs:79
FreeLance.Data.Framework.EntityFramework.Repository`1.GetAll(Expression`1[] include) in C:\Phase2\FreeLance\FreeLance\Framework\Data\FreeLance.Data.Framework\EntityFramework\Repository.cs:89
FreeLance.Business.PageBC.GetPages() in C:\Phase2\FreeLance\FreeLance\Business\FreeLance.Business\Admin\PageBC.cs:49
FreeLance.Services.PageService.GetPages() in C:\Phase2\FreeLance\FreeLance\Services\FreeLance.Services\PageService.cs:54
FreeLance.Web.Helpers.DataHelper.GetAppPages() in C:\Phase2\FreeLance\FreeLance\User Interface\FreeLance.Web\Helpers\DataHelper.cs:250
FreeLance.Web.ResourceConfig.GetAppPages() in C:\Phase2\FreeLance\FreeLance\User Interface\FreeLance.Web\App_Start\ResourceConfig.cs:64
FreeLance.Web.AppConfig.Run() in C:\Phase2\FreeLance\FreeLance\User Interface\FreeLance.Web\App_Start\AppConfig.cs:55
FreeLance.Web.MvcApplication.Application_Start() in C:\Phase2\FreeLance\FreeLance\User Interface\FreeLance.Web\Global.asax.cs:40
[HttpException (0x80004005): Failed to find or load the registered .Net Framework Data Provider.]
System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) +4054645
System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +191
System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +352
System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +407
System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +375
[HttpException (0x80004005): Failed to find or load the registered .Net Framework Data Provider.]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +11646640
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +141
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +4869909
采纳答案by Prado
Make sure you have added MySql.Data.Entity.dll& MySql.Data.dllfiles in the bin of the MVC project
确保您已在 MVC 项目的 bin 中添加了MySql.Data.Entity.dll和MySql.Data.dll文件
回答by Daniel Kmak
If using Mono make sure you also have MySQL Data Provider node in machine.config. I'm using 4.5 so for meit's /opt/mono/4.5/machine.config(example location):
如果使用 Mono,请确保在 machine.config 中还有 MySQL Data Provider 节点。我使用的是 4.5,所以对我来说它是/opt/mono/4.5/machine.config(示例位置):
<system.data>
<DbProviderFactories>
<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.8.3.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
</DbProviderFactories>
</system.data>
You can find machine.config location by running simple command in Linux:
你可以通过在 Linux 中运行简单的命令来找到 machine.config 的位置:
cd / && find -name 'machine.config'
You may need sudo
before find
command on Ubuntu:
您可能需要在 Ubuntu 上使用sudo
beforefind
命令:
cd / && sudo find -name 'machine.config'