Failed to find or load the registered .Net Framework Data Provider with MySql + MVC4

asp.net-mvc-4 azure c# entity-framework mysql

Question

We are getting the following error when we tried running our MVC4 Project with Azure Mysql DB.

In Web.Config file we have the following,

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

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
1
12
9/6/2013 12:11:23 PM

Accepted Answer

Make sure you have added MySql.Data.Entity.dll & MySql.Data.dll files in the bin of the MVC project

20
2/6/2014 9:05:14 AM

Popular Answer

If using Mono make sure you also have MySQL Data Provider node in machine.config. I'm using 4.5 so for me it's /opt/mono/4.5/machine.config(example location):

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

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

You may need sudo before find command on Ubuntu:

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


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow