12

当我们尝试使用 Azure Mysql DB 运行 MVC4 项目时,出现以下错误。

在 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>

错误:

未能找到或加载已注册的 .Net Framework 数据提供程序。

说明:执行当前 Web 请求期间发生未处理的异常。请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息。

异常详细信息:System.Configuration.ConfigurationErrorsException:无法找到或加载已注册的 .Net Framework 数据提供程序。

源错误:

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
4

2 回答 2

21

确保在 MVC 项目的 bin 中添加了MySql.Data.Entity.dllMySql.Data.dll文件

于 2014-02-06T09:05:14.877 回答
4

如果使用 Mono,请确保您在 machine.config 中也有 MySQL 数据提供程序节点。我使用的是 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>

您可以通过在 Linux 中运行简单的命令找到 machine.config 位置:

cd / && find -name 'machine.config'

在 Ubuntu 上您可能需要sudobeforefind命令:

cd / && sudo find -name 'machine.config'
于 2014-09-16T22:26:30.227 回答