C# 使用asp.net的MySql有错误

C# 使用asp.net的MySql有错误,c#,mysql,asp.net,C#,Mysql,Asp.net,帮助我访问mysql数据库。存在连接,但存在另一个错误。我无法连接到数据库(本地)。错误: 跟踪堆栈: [MethodAccessException: Методу "MySql.Data.MySqlClient.MySqlProviderServices.GetDbProviderManifestToken(System.Data.Common.DbConnection)" could not access the method"MySql.Data.MySqlClient.MySqlConn

帮助我访问mysql数据库。存在连接,但存在另一个错误。我无法连接到数据库(本地)。错误:

跟踪堆栈:

[MethodAccessException: Методу "MySql.Data.MySqlClient.MySqlProviderServices.GetDbProviderManifestToken(System.Data.Common.DbConnection)" could not access the method"MySql.Data.MySqlClient.MySqlConnection.get_Settings()".]
   MySql.Data.MySqlClient.MySqlProviderServices.GetDbProviderManifestToken(DbConnection connection) +44
   System.Data.Entity.Core.Common.DbProviderServices.GetProviderManifestToken(DbConnection connection) +87

[ProviderIncompatibleException: The provider did not return a ProviderManifestToken string.]
   System.Data.Entity.Core.Common.DbProviderServices.GetProviderManifestToken(DbConnection connection) +271
   MySql.Data.Entity.MySqlManifestTokenResolver.ResolveManifestToken(DbConnection connection) +32
   System.Data.Entity.Utilities.DbConnectionExtensions.GetProviderInfo(DbConnection connection, DbProviderManifest& providerManifest) +56
   System.Data.Entity.DbModelBuilder.Build(DbConnection providerConnection) +43
   System.Data.Entity.Internal.LazyInternalContext.CreateModel(LazyInternalContext internalContext) +62
   System.Data.Entity.Internal.RetryLazy`2.GetValue(TInput input) +123
   System.Data.Entity.Internal.LazyInternalContext.InitializeContext() +627
   System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType) +18
   System.Data.Entity.Internal.Linq.InternalSet`1.Initialize() +53
   System.Data.Entity.Internal.Linq.InternalSet`1.GetEnumerator() +15
   System.Data.Entity.Infrastructure.DbQuery`1.System.Collections.Generic.IEnumerable<TResult>.GetEnumerator() +53
   System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) +375
   System.Linq.Enumerable.ToList(IEnumerable`1 source) +58
   WebApplication2.Controllers.HomeController.Index() in C:\Users\shebanits.vitaliy\source\repos\WebApplication2\WebApplication2\Controllers\HomeController.cs:24
   lambda_method(Closure , ControllerBase , Object[] ) +62
   System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +14
   System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +157
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +27
   System.Web.Mvc.Async.<>c.<BeginInvokeSynchronousActionMethod>b__9_0(IAsyncResult asyncResult, ActionInvocation innerInvokeState) +22
   System.Web.Mvc.Async.WrappedAsyncResult`2.CallEndDelegate(IAsyncResult asyncResult) +29
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) +32
   System.Web.Mvc.Async.AsyncInvocationWithFilters.<InvokeActionMethodFilterAsynchronouslyRecursive>b__11_0() +50
   System.Web.Mvc.Async.<>c__DisplayClass11_1.<InvokeActionMethodFilterAsynchronouslyRecursive>b__2() +228
   System.Web.Mvc.Async.<>c__DisplayClass7_0.<BeginInvokeActionMethodWithFilters>b__1(IAsyncResult asyncResult) +10
   System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +10
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) +34
   System.Web.Mvc.Async.<>c__DisplayClass3_6.<BeginInvokeAction>b__3() +35
   System.Web.Mvc.Async.<>c__DisplayClass3_1.<BeginInvokeAction>b__5(IAsyncResult asyncResult) +100
   System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +10
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +27
   System.Web.Mvc.<>c.<BeginExecuteCore>b__152_1(IAsyncResult asyncResult, ExecuteCoreState innerState) +11
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +29
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
   System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +45
   System.Web.Mvc.<>c.<BeginExecute>b__151_2(IAsyncResult asyncResult, Controller controller) +13
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +22
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
   System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +26
   System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +10
   System.Web.Mvc.<>c.<BeginProcessRequest>b__20_1(IAsyncResult asyncResult, ProcessRequestState innerState) +28
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +29
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
   System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +28
   System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9748665
   System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step) +48
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +159

我怀疑您使用的是
MySql.Data
v8.0.11和
MySql.Data.Entity
v6.10.7。它们有不同的主要版本,不兼容


您需要卸载MySql.Data.Entity并安装;Oracle作为升级到v8.x的一部分。

我不太出名,因此无法对Bradley Grainger的答案发表评论,但8.x EF版本是可用的,但(重新)实现并不明显


根据发行说明,您需要安装nuget包MySql.Data.EntityFramework并删除包MySql.Data.Entity以使用8.x驱动程序,但出现了相同的错误,并尝试了您编写的所有操作

Project -> Clean

Project -> Rebuild

问题已解决。

安装的
MySql.Data v6.10.7
MySql.Data.Entity v6.10.7
可能重复。错误仍然存在。需要安装什么版本?@bааааааааааааааа1072?请尝试清理和重建所有内容,并确保
bin
目录中的
MySql.Data.dll
实际上是6.10.7,而不是8.0.11。
 <entityFramework codeConfigurationType="MySql.Data.Entity.MySqlEFConfiguration, MySql.Data.Entity.EF6">
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
    <providers>
      <provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6" /> 
    </providers>
  </entityFramework>
  <connectionStrings>
    <add name="conn" providerName="MySql.Data.MySqlClient"
         connectionString="server=127.0.0.1;uid=root;Password=Accessdeniedroma2005;database=musicportal;CharSet=utf8;Persist Security Info=False;Integrated Security=true" />
  </connectionStrings>
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Web;

namespace WebApplication2.Models
{
    public class User
    {
        public int id { get; set; }
        public string login { get; set; }
        public string password { get; set; }
        public string username { get; set; }
    }

    [DbConfigurationType(typeof(MySql.Data.Entity.MySqlEFConfiguration))]
    public class UsersContext : DbContext
    {
        public UsersContext() : base("conn")
        {  }

        public DbSet<User> Users { get; set; }
    }
}
private UsersContext dbUsers = new UsersContext();
        public ActionResult Index()
        {
            //string connectionString = @"Data Source=localhost; Database = musicportal; User ID = root; Password = Accessdeniedroma2005;SslMode=none";
            //using (MySqlConnection cn = new MySqlConnection(connectionString))
            //{
            //    cn.Open();
            //    Response.Write("Подключился!");
            //}

            return View(dbUsers.Users.ToList());
        }
Project -> Clean

Project -> Rebuild