c# - 无法找到请求的.Net Framework 数据提供程序

标签 c# mysql asp.net-mvc-3 razor

我使用 Visual Studio 2010 Ultimate,项目是 c# MVC3 Razor

我有一个项目,使用 MySql(来自在线服务器)数据库在本地计算机上运行没有任何问题,但是当我上传它并且当它到达需要从 MySql 服务器获取数据的部分时,它会给出我这个错误:

Unable to find the requested .Net Framework Data Provider. It may not be installed.

这是我来自 Web.config 的 MySql 连接字符串,当我在本地调试项目时,它运行良好。从表格中读取信息并显示在页面上。

<add name="istakipDBContext" 
connectionString="Server=xxx.xxx.xxx.xxx; Database=xxx; Uid=xxx;
Pwd=xxx;"  providerName="MySql.Data.MySqlClient" />

这是整个堆栈跟踪:

Server Error in '/' Application. Unable to find the requested .Net Framework Data Provider. It may not be installed. 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.ArgumentException: Unable to find the requested .Net Framework Data Provider. It may not be installed.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[ArgumentException: Unable to find the requested .Net Framework Data Provider. It may not be installed.]
System.Data.Common.DbProviderFactories.GetFactory(String providerInvariantName) +1420503
System.Data.Entity.Internal.LazyInternalConnection.TryInitializeFromAppConfig(String name) +393
System.Data.Entity.Internal.LazyInternalConnection.Initialize() +47
System.Data.Entity.Internal.LazyInternalConnection.get_ConnectionHasModel() +9 System.Data.Entity.Internal.LazyInternalContext.InitializeContext() +262 System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType) +17
System.Data.Entity.Internal.Linq.InternalSet1.Initialize() +63<br/> System.Data.Entity.Internal.Linq.InternalSet1.GetEnumerator() +15
System.Data.Entity.Infrastructure.DbQuery1.System.Collections.Generic.IEnumerable<TResult>.GetEnumerator() +40 System.Collections.Generic.List1..ctor(IEnumerable1 collection) +315 System.Linq.Enumerable.ToList(IEnumerable1 source) +58 onlinetercume.Controllers.istakiplerController.Index() in C:\wwwroot\nps\nps\Controllers\istakiplerController.cs:21 lambda_method(Closure , ControllerBase , Object[] ) +62
System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +17
System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary2 parameters) +208<br/> System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary2 parameters) +27
System.Web.Mvc.<>c_DisplayClass15.b_12() +55 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func1 continuation) +263<br/> System.Web.Mvc.<>c__DisplayClass17.<InvokeActionMethodWithFilters>b__14() +19 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList1 filters, ActionDescriptor actionDescriptor, IDictionary2 parameters) +191<br/> System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +343<br/> System.Web.Mvc.Controller.ExecuteCore() +116<br/> System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +97 System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +10<br/> System.Web.Mvc.<>c__DisplayClassb.<BeginProcessRequest>b__5() +37<br/> System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +21<br/> System.Web.Mvc.Async.<>c__DisplayClass81.b__7(IAsyncResult ) +12 System.Web.Mvc.Async.WrappedAsyncResult`1.End() +62 System.Web.Mvc.<>c_DisplayClasse.b_d() +50
System.Web.Mvc.SecurityUtil.b
_0(Action f) +7 System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action) +22 System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +60
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +8970061 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +184

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.272

最佳答案

错误很明显,找不到MySQL数据提供者

如果您部署到生产服务器,也许您还没有部署 MySQL 组件,请检查您是否已将 MySQL dll 部署到应用程序的 bin 文件夹中

一个常见问题是,当您在开发沙箱的 GAC 中安装了组件,但它们不存在于生产服务器中时,请验证 dll 是否在 GAC 中:

全局程序集缓存 (GAC) 位于:%windir%\assembly

但是,如果将程序集配置为解析来自 GAC 的引用,您可以通过将程序集的“始终复制”属性选择为 true,强制将项目中的引用部署到生产服务器那么最好将该组件安装在生产盒中的 GAC 中:

enter image description here

enter image description here

以下是在 GAC 中安装 MySQL 数据提供程序的步骤

http://blog.jeffreymcmanus.com/555/installing-the-mysql-adonet-connector-into-the-global-assembly-cache/

总结:

  • 解决方案 1:

    运行以下命令在 GAC 中注册 MySQL 数据提供程序(这样,该版本的 MySQL 数据提供程序将全局安装,可供服务器中的所有应用程序使用)

    “C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\gacutil.exe”/i MySql.Data.dll

  • 解决方案 2:

    MySql.Data.dll dll 复制到应用程序的 bin 目录

关于c# - 无法找到请求的.Net Framework 数据提供程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10843728/

相关文章:

asp.net-mvc - 发布表单数据后如何使用 ModelState 清除表单,我的 View 模型是一个具有两个模型的 View 模型?

asp.net-mvc-3 - MVC 按钮点击操作

c# - 在强类型 View 中使用 LabelFor 获取 "Object does not contain a definition for xxx"

c# - 将 UWP App 连接到远程 SQL Server 2008 提供程序 : TCP Provider, 错误:0

c# - WCF maxReceivedMessageSize 不能设置超过 4215

c# - 使用动态值构造的名称定义对象

php - Drupal db_select PDO 语句 : ORDER BY CASE

c# - 在 C# 中将 mysql 读取器结果转换为字符串会引发异常

mysql - 正确使用mysql中的where?

c# - 增加已启动 session 的超时时间