如何在 Mono Ubuntu 上找到 MySql 的 .Net Framework 数据提供程序的存在?

Posted

技术标签:

【中文标题】如何在 Mono Ubuntu 上找到 MySql 的 .Net Framework 数据提供程序的存在?【英文标题】:How to find existence of .Net Framework Data Provider for MySql on Mono Ubuntu? 【发布时间】:2016-01-25 08:03:41 【问题描述】:

solving basic porting issues 之后,我试图从 ASP.NET Mono 项目连接到 mysql 数据库。

每当我尝试连接数据库时,都会抛出以下错误(请运行 sn -p):

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<style type="text/css">
body  background-color: #FFFFFF; font-size: .75em; font-family: Verdana, Helvetica, Sans-Serif; margin: 0; padding: 0;	color: #696969; 
a:link  color: #000000; text-decoration: underline; 
a:visited  color: #000000; 
a:hover  color: #000000; text-decoration: none; 
a:active  color: #12eb87; 
p, ul 	margin-bottom: 20px; line-height: 1.6em; 
pre  font-size: 1.2em;	margin-left: 20px; margin-top: 0px; 
h1, h2, h3, h4, h5, h6  font-size: 1.6em; color: #000;	font-family: Arial, Helvetica, sans-serif; 
h1  font-weight: bold;	margin-bottom: 0; margin-top: 0; padding-bottom: 0; 
h2  font-size: 1em; padding: 0 0 0px 0; color: #696969; font-weight: normal; margin-top: 0; margin-bottom: 20px; 
h2.exceptionMessage  white-space: pre; 
h3  font-size: 1.2em; 
h4  font-size: 1.1em; 
h5, h6  font-size: 1em; 
#header  position: relative; margin-bottom: 0px; color: #000; padding: 0; background-color: #5c87b2; height: 38px; padding-left: 10px; 
#header h1  font-weight: bold;	padding: 5px 0;	margin: 0; color: #fff;	border: none; line-height: 2em;	font-family: Arial, Helvetica, sans-serif; font-size: 32px !important; 
#header-image  float: left; padding: 3px; margin-left: 1px; margin-right: 1px; 
#header-text  color: #fff; font-size: 1.4em; line-height: 38px; font-weight: bold; 
#main 	padding: 20px 20px 15px 20px; background-color: #fff; _height: 1px; 
#footer  color: #999; padding: 5px 0; text-align: left; line-height: normal; margin: 20px 0px 0px 0px;	font-size: .9em; border-top: solid 1px #5C87B2; 
#footer-powered-by  float: right; 
.details  font-family: monospace; border: solid 1px #e8eef4; white-space: pre; font-size: 1.2em; overflow: auto; padding: 6px; margin-top: 6px; background-color: #eeeeff; color: 555555 
.details-wrapped  white-space: normal 
.details-header  margin-top: 1.5em 
.details-header a  font-weight: bold; text-decoration: none 
p  margin-bottom: 0.3em; margin-top: 0.1em 
.sourceErrorLine  color: #770000; font-weight: bold; 
</style>
<script type="text/javascript">
	var hideElementsById = new Array ();
	window.onload = function () 
		if (!hideElementsById || hideElementsById.length < 1)
			return;
		for (index in hideElementsById)
			toggle (hideElementsById [index]);
	
	
	function toggle (divId)
	
		var e = document.getElementById (divId);
		if (!e)
			return;
		var h = document.getElementById (divId + "Hint");
		if (e.style.display == "block" || e.style.display == "") 
			e.style.display = "none";
			if (h)
				h.innerHTML = " (click to show)";
		 else 
			e.style.display = "block";
			if (h)
				h.innerHTML = " (click to hide)";
		
	
</script>
<title>Error 500</title>
</head>
<body>
<div class="page">
<div id="header">
<div id="header-text">Application Exception</div>
</div>
<div id="main">
  <h1>System.ArgumentException</h1>
  <h2 class="exceptionMessage">Unable to find the requested .Net Framework Data Provider.  It may not be installed.</h2>
  <p><strong>Description:</strong> HTTP 500.Error processing request.</p><p><strong>Details:</strong> Non-web exception. Exception origin (name of application or object): System.Data.</p>
<div><strong>Exception stack trace:</strong></div>
<div class="details">  at System.Data.Common.DbProviderFactories.GetFactory (System.String providerInvariantName) [0x00036] in &lt;filename unknown&gt;:0 
  at System.Data.Entity.Infrastructure.DependencyResolution.DefaultProviderFactoryResolver.GetService (System.Type type, System.Object key, System.Func`3 handleFailedLookup) [0x0003b] in &lt;filename unknown&gt;:0 </div><div id="footer">
  <div style="color:Black;"><strong>Version Information:</strong> <tt>4.2.1 (Stable 4.2.1.102/6dd2d0d Thu Nov 12 09:52:44 UTC 2015)</tt>; ASP.NET Version: <tt>4.0.30319.17020</tt></div>
  <div id="footer-powered-by">Powered by <a href="http://mono-project.com/">Mono</a></div>
</div>
</div>
</div>
</body>
</html>

<!--
[System.ArgumentException]: The ADO.NET provider with invariant name &#39;MySql.Data.MySqlClient&#39; is either not registered in the machine or application config file, or could not be loaded. See the inner exception for details.
  at System.Data.Entity.Infrastructure.DependencyResolution.DefaultProviderFactoryResolver.<GetService>b__0 (System.ArgumentException e, System.String n) [0x0000c] in <filename unknown>:0 
  at System.Data.Entity.Infrastructure.DependencyResolution.DefaultProviderFactoryResolver.GetService (System.Type type, System.Object key, System.Func`3 handleFailedLookup) [0x00045] in <filename unknown>:0 
  at System.Data.Entity.Infrastructure.DependencyResolution.DefaultProviderFactoryResolver.GetService (System.Type type, System.Object key) [0x00000] in <filename unknown>:0 
  at System.Data.Entity.Infrastructure.DependencyResolution.CachingDependencyResolver+<>c__DisplayClass1.<GetService>b__0 (System.Tuple`2 k) [0x00000] in <filename unknown>:0 
  at System.Collections.Concurrent.ConcurrentDictionary`2[TKey,TValue].GetOrAdd (System.Collections.Concurrent.TKey key, System.Func`2 valueFactory) [0x00037] in <filename unknown>:0 
  at System.Data.Entity.Infrastructure.DependencyResolution.CachingDependencyResolver.GetService (System.Type type, System.Object key) [0x00032] in <filename unknown>:0 
  at System.Data.Entity.Infrastructure.DependencyResolution.ResolverChain+<>c__DisplayClass3.<GetService>b__0 (IDbDependencyResolver r) [0x00000] in <filename unknown>:0 
  at System.Linq.Enumerable+WhereSelectArrayIterator`2[TSource,TResult].MoveNext () [0x0004d] in <filename unknown>:0 
  at System.Linq.Enumerable.FirstOrDefault[TSource] (IEnumerable`1 source, System.Func`2 predicate) [0x00048] in <filename unknown>:0 
  at System.Data.Entity.Infrastructure.DependencyResolution.ResolverChain.GetService (System.Type type, System.Object key) [0x0002d] in <filename unknown>:0 
  at System.Data.Entity.Infrastructure.DependencyResolution.RootDependencyResolver.GetService (System.Type type, System.Object key) [0x00022] in <filename unknown>:0 
  at System.Data.Entity.Infrastructure.DependencyResolution.ResolverChain+<>c__DisplayClass3.<GetService>b__0 (IDbDependencyResolver r) [0x00000] in <filename unknown>:0 
  at System.Linq.Enumerable+WhereSelectArrayIterator`2[TSource,TResult].MoveNext () [0x0004d] in <filename unknown>:0 
  at System.Linq.Enumerable.FirstOrDefault[TSource] (IEnumerable`1 source, System.Func`2 predicate) [0x00048] in <filename unknown>:0 
  at System.Data.Entity.Infrastructure.DependencyResolution.ResolverChain.GetService (System.Type type, System.Object key) [0x0002d] in <filename unknown>:0 
  at System.Data.Entity.Infrastructure.DependencyResolution.CompositeResolver`2[TFirst,TSecond].GetService (System.Type type, System.Object key) [0x00021] in <filename unknown>:0 
  at System.Data.Entity.Infrastructure.DependencyResolution.DbDependencyResolverExtensions.GetService[T] (IDbDependencyResolver resolver, System.Object key) [0x0000c] in <filename unknown>:0 
  at System.Data.Entity.Internal.LazyInternalConnection.CreateConnectionFromProviderName (System.String providerInvariantName) [0x00005] in <filename unknown>:0 
  at System.Data.Entity.Internal.LazyInternalConnection.InitializeFromConnectionStringSetting (System.Configuration.ConnectionStringSettings appConfigConnection) [0x0003b] in <filename unknown>:0 
  at System.Data.Entity.Internal.LazyInternalConnection.TryInitializeFromAppConfig (System.String name, System.Data.Entity.Internal.AppConfig config) [0x0000b] in <filename unknown>:0 
  at System.Data.Entity.Internal.LazyInternalConnection.Initialize () [0x0005b] in <filename unknown>:0 
  at System.Data.Entity.Internal.LazyInternalConnection.get_ProviderName () [0x00000] in <filename unknown>:0 
  at System.Data.Entity.Internal.LazyInternalContext.get_ProviderName () [0x00000] in <filename unknown>:0 
  at System.Data.Entity.Internal.DefaultModelCacheKeyFactory.Create (System.Data.Entity.DbContext context) [0x0002b] in <filename unknown>:0 
  at System.Data.Entity.Internal.LazyInternalContext.InitializeContext () [0x0009b] in <filename unknown>:0 
  at System.Data.Entity.Internal.InternalContext.Initialize () [0x00000] in <filename unknown>:0 
  at System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType (System.Type entityType) [0x00000] in <filename unknown>:0 
  at System.Data.Entity.Internal.Linq.InternalSet`1[TEntity].Initialize () [0x0000e] in <filename unknown>:0 
  at System.Data.Entity.Internal.Linq.InternalSet`1[TEntity].get_InternalContext () [0x00000] in <filename unknown>:0 
  at System.Data.Entity.Infrastructure.DbQuery`1[TResult].System.Linq.IQueryable.get_Provider () [0x00016] in <filename unknown>:0 
  at System.Data.Entity.QueryableExtensions.FirstOrDefaultAsync[TSource] (IQueryable`1 source, System.Linq.Expressions.Expression`1 predicate, CancellationToken cancellationToken) [0x0001f] in <filename unknown>:0 
  at System.Data.Entity.QueryableExtensions.FirstOrDefaultAsync[TSource] (IQueryable`1 source, System.Linq.Expressions.Expression`1 predicate) [0x0001f] in <filename unknown>:0 
  at Microsoft.AspNet.Identity.EntityFramework.UserStore`6+<GetUserAggregateAsync>d__6c[TUser,TRole,TKey,TUserLogin,TUserRole,TUserClaim].MoveNext () [0x000d9] in <filename unknown>:0 
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <filename unknown>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0004e] in <filename unknown>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in <filename unknown>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in <filename unknown>:0 
  at System.Runtime.CompilerServices.TaskAwaiter`1[TResult].GetResult () [0x00000] in <filename unknown>:0 
  at Microsoft.AspNet.Identity.TaskExtensions+CultureAwaiter`1[T].GetResult () [0x0000c] in <filename unknown>:0 
  at Microsoft.AspNet.Identity.Owin.SignInManager`2+<PasswordSignInAsync>d__29[TUser,TKey].MoveNext () [0x000ad] in <filename unknown>:0 
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <filename unknown>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0004e] in <filename unknown>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in <filename unknown>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in <filename unknown>:0 
  at System.Runtime.CompilerServices.TaskAwaiter`1[TResult].GetResult () [0x00000] in <filename unknown>:0 
  at UI.Controllers.AccountController+<Login>c__async4.MoveNext () [0x00123] in /home/xameeramir/Projects/UI/UI/Controllers/AccountController.cs:337 
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <filename unknown>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0004e] in <filename unknown>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in <filename unknown>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in <filename unknown>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.GetResult () [0x00000] in <filename unknown>:0 
  at System.Threading.Tasks.TaskHelpersExtensions.ThrowIfFaulted (System.Threading.Tasks.Task task) [0x00007] in <filename unknown>:0 
  at System.Web.Mvc.Async.TaskAsyncActionDescriptor.EndExecute (IAsyncResult asyncResult) [0x0000d] in <filename unknown>:0 
  at System.Web.Mvc.Async.AsyncControllerActionInvoker+<>c__DisplayClass37.<BeginInvokeAsynchronousActionMethod>b__36 (IAsyncResult asyncResult) [0x00000] in <filename unknown>:0 
  at System.Web.Mvc.Async.AsyncResultWrapper+WrappedAsyncResult`1[TResult].CallEndDelegate (IAsyncResult asyncResult) [0x00000] in <filename unknown>:0 
  at System.Web.Mvc.Async.AsyncResultWrapper+WrappedAsyncResultBase`1[TResult].End () [0x00029] in <filename unknown>:0 
  at System.Web.Mvc.Async.AsyncResultWrapper.End[TResult] (IAsyncResult asyncResult, System.Object tag) [0x00007] in <filename unknown>:0 
  at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod (IAsyncResult asyncResult) [0x00000] in <filename unknown>:0 
  at System.Web.Mvc.Async.AsyncControllerActionInvoker+AsyncInvocationWithFilters.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3d () [0x00014] in <filename unknown>:0 
  at System.Web.Mvc.Async.AsyncControllerActionInvoker+AsyncInvocationWithFilters+<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f () [0x00002] in <filename unknown>:0 

[System.ArgumentException]: Unable to find the requested .Net Framework Data Provider.  It may not be installed.
  at System.Data.Common.DbProviderFactories.GetFactory (System.String providerInvariantName) [0x00036] in <filename unknown>:0 
  at System.Data.Entity.Infrastructure.DependencyResolution.DefaultProviderFactoryResolver.GetService (System.Type type, System.Object key, System.Func`3 handleFailedLookup) [0x0003b] in <filename unknown>:0 
-->

摘自web.config

<entityFramework>
<providers>
  <provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6"/>
  <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer"/>
</providers>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework" >
  <parameters>
    <parameter value="mssqllocaldb"/>
  </parameters>
</defaultConnectionFactory>
</entityFramework>
如何确定请求的.Net Framework Data Provider 确实已安装?

非常感谢任何帮助!

【问题讨论】:

你有MySqlClient dll的引用吗? system.data.sqlite.org/index.html/info/2be4298631(该链接适用于 SQLite,但适用于所有 ADO.NET 提供程序)您还必须配置 &lt;system.data&gt; 部分,或者 Mono 如何加载提供程序? 作为一个警告,不要使用 cmets 来请别人回答你的问题。这些在整个网站上都被标记了,我已经删除了所有我找到的。 @BradLarson 哎呀,我的目的纯粹是为了引起人们对这些问题的关注。除了 cmets,你还有什么推荐的?顺便说一句,在这种情况下,您使用 cmets 做什么? Lolz 另外,感谢您为清洁 SO 所做的努力 :) @student - 如果人们想回答你的问题,他们会想办法解决的。评论将用于澄清问题或答案,或提供补充信息。我只为此使用了评论,因为我不想直接发送版主消息,这会在您的帐户中留下永久记录。 【参考方案1】:

您可以使用此代码(采用https://msdn.microsoft.com/en-us/library/12kxkt25(v=vs.80).aspx)列出所有提供商。在我的具有不变名称 MySql.Data.MySqlClient" 的环境提供程序中没有列出

using System;
using System.Collections.Generic;
using System.Text;
using System.Data.Common;
using System.Data;

namespace ConsoleApplication3

    class Program
    
        static void Main(string[] args)
        
            DataTable table = DbProviderFactories.GetFactoryClasses();

            // Display each row and column value.
            foreach (DataRow row in table.Rows)
            
                foreach (DataColumn column in table.Columns)
                
                    Console.WriteLine("0:1",column.ColumnName,  row[column]);
                
                Console.WriteLine("----------------------------");
            

        
    

【讨论】:

我会检查一下然后回来

以上是关于如何在 Mono Ubuntu 上找到 MySql 的 .Net Framework 数据提供程序的存在?的主要内容,如果未能解决你的问题,请参考以下文章

如何在Ubuntu 16.04上安装mono 4.8

在 Mono 上运行 ASP.NET 5 的 Ubuntu 上使用 MVC 6 调整图像大小

在Ubuntu上安装Mono

十分钟内在Ubuntu系统上搭建Mono开发环境(Mono软件Ubuntu系统国内镜像源Mono国内镜像源)

如何在 Mono 上将 Linq 与 MySql 数据库一起使用?

在 ubuntu 上使用 mono 的 C# DLLimport:不收取 dll