解决了基本的移植问题之后 ,我尝试从ASP.NET Mono项目连接到MySql数据库。
每当我尝试连接到数据库时,都会抛出以下错误(请运行代码段):
<?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 <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 </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 'MySql.Data.MySqlClient' 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
确实已安装? 任何帮助深表感谢!
您可以使用此代码列出所有提供者(采取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("----------------------------"); } } } }