简体   繁体   中英

Problems connecting ASP.NET MVC3 website to MySQL

I'm having problems connecting my website (asp.net mvc3) to MySQL.

Localhost is working, but on the server I receive the following error:

Error: Unable to locate the Data Provider. Requested Net Framework. Maybe it is not installed.

Stacktrace: [ArgumentException: The repository provider specified is not found in the configuration or is not valid.]
System.Data.EntityClient.EntityConnection.GetFactory(String providerString) +11468668
System.Data.EntityClient.EntityConnection.ChangeConnectionString(String newConnectionString) +575
System.Data.Entity.Internal.LazyInternalConnection.TryInitializeFromAppConfig(String name, AppConfig config) +144 ... +21 System.Data.Entity.Infrastructure.DbQuery 1.System.Linq.IQueryable.get_Provider() +44 System.Linq.Queryable.Where(IQueryable 1 source, Expression 1 predicate) +85 AcusticoA3.Controllers.HomeController.Index() +978 lambda_method(Closure , ControllerBase , Object[] ) +79
System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary
1 predicate) +85 AcusticoA3.Controllers.HomeController.Index() +978 lambda_method(Closure , ControllerBase , Object[] ) +79
System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary
1 predicate) +85 AcusticoA3.Controllers.HomeController.Index() +978 lambda_method(Closure , ControllerBase , Object[] ) +79
System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary
2 parameters) +264

System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary 2 parameters) +39
System.Web.Mvc.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12() +124 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func
2 parameters) +39
System.Web.Mvc.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12() +124 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func
2 parameters) +39
System.Web.Mvc.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12() +124 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func
1 continuation) +727142 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList 1 filters, ActionDescriptor actionDescriptor, IDictionary 2 parameters) +309

System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +727076
System.Web.Mvc.Controller.ExecuteCore() +159
System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +334 System.Web.Mvc.<>c_ DisplayClassb.b _5() +62 System.Web.Mvc.Async.<>c_ DisplayClass1.b _0() +15 System.Web.Mvc.<>c_ DisplayClasse.b _d() +52
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +606 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +288

I'm using Mysql.connector 6.6.5.0 and EntityFramework 5.0.

My connectionstring:

  <connectionStrings>
    <add name="MyEntities" connectionString="metadata=res://*/Models.Model.csdl|res://*/Models.Model.ssdl|res://*/Models.Model.msl;provider=MySql.Data.MySqlClient;provider connection string=&quot;server=[HOST];user id=[USER]; password=[PASSWORD]; database=[DATABASE]&quot;" providerName="System.Data.EntityClient"/>   </connectionStrings>

I resolved.

Just put the provider dlls in the bin folder and do the setting in Web.config:

  <system.data>
    <DbProviderFactories>
      <clear />
      <remove invariant="MySQL Data Provider"/>
      <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.6.5.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />     
    </DbProviderFactories>   </system.data>

Just remember to change the provider version.

You can also tell the compiler to copy these files in the bin directory, by setting "Copy Local" to True :

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM