MySql with asp.net have error

Help me access the mysql database. There is a connection, but there is another error.I can not connect to the database (local). Error:

Server Error in Application '/'.
Method "MySql.Data.MySqlClient.MySqlProviderServices.GetDbProviderManifestToken(System.Data.Common.DbConnection)" could not access the method "MySql.Data.MySqlClient.MySqlConnection.get_Settings()".

Description: An unhandled exception occurred during the execution of the current web request. Examine the stack trace for more information about this error and the code snippet that caused it. 

Exclusion Information: System.MethodAccessException: Method "MySql.Data.MySqlClient.MySqlProviderServices.GetDbProviderManifestToken(System.Data.Common.DbConnection)" could not access the method "MySql.Data.MySqlClient.MySqlConnection.get_Settings()".

Trace the stack:

[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

I understand that I can not connect to the database, but I do not understand what the error is, tell me. Here is the code ...

web.config

 <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>

Model with contex:

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; }
    }
}

and part of the controller::

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());
        }

Upvotes: 1

Views: 1243

Answers (3)

vlad mosiytchuk
vlad mosiytchuk

Reputation: 1

Had the same error and tried everything you wrote...

Project -> Clean

Project -> Rebuild

Problem solved.

Upvotes: -1

Bradley Grainger
Bradley Grainger

Reputation: 28162

I suspect you're using MySql.Data v8.0.11 and MySql.Data.Entity v6.10.7. These have different major versions and are not compatible.

You need to uninstall MySql.Data.Entity and install MySql.Data.EntityFramework instead; Oracle changed the name as part of the upgrade to v8.x.

Upvotes: 3

joel.cass
joel.cass

Reputation: 43

I'm not famous enough so cannot comment on the answer from Bradley Grainger, but the 8.x EF release is available, but the (re)implementation is not that obvious.

Per release notes https://forums.mysql.com/read.php?3,661134 you need to install the nuget package MySql.Data.EntityFramework and remove the package MySql.Data.Entity to use the 8.x driver

Upvotes: 0

Related Questions