UserManager CreateAsync上的连接错误

Dev*_*lek 2 mysql asp.net-identity entity-framework-core asp.net-core

尝试使用UserManager CreateAsync方法创建新用户时出现以下错误.我使用的是未经修改的IdentityUser和IdentityRole.我有几个DBSets填充了数据库中的数据,所以阅读不是问题,只是写它似乎.

    {System.InvalidOperationException: Connection must be valid and open to commit transaction at MySql.Data.MySqlClient.MySqlTransaction.Commit()
   at Microsoft.EntityFrameworkCore.Storage.RelationalTransaction.Commit()
   at Microsoft.EntityFrameworkCore.Update.Internal.BatchExecutor.<ExecuteAsync>d__10.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.<SaveChangesAsync>d__54.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.<SaveChangesAsync>d__52.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.EntityFrameworkCore.DbContext.<SaveChangesAsync>d__35.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Identity.EntityFrameworkCore.UserStore`9.<CreateAsync>d__36.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Identity.UserManager`1.<CreateAsync>d__68.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Identity.UserManager`1.<CreateAsync>d__73.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at Controllers.Auth.AuthController.<Register>d__9.MoveNext() in AuthController.cs:line 102}
Run Code Online (Sandbox Code Playgroud)

我正在使用;

  • MySQL实体框架核心7.0.7-m61
  • Visual Studio 2017
  • ASP.NET Core MVC 1.1.0
  • 身份1.1

错误中提到的第102行是var result = await userManager.CreateAsync(newUser,model.Password);

        [HttpPost]
        public async Task<ActionResult>Register(RegisterViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var newUser = new IdentityUser
                    {
                        Email = model.Email,
                        UserName = model.Username
                    };

                    var result = await _userManager.CreateAsync(newUser, model.Password);

                    if (result.Succeeded)
                    {
                        await _signInManager.SignInAsync(newUser, false);
                        _logger.LogInformation($"New user account created: {model.Username}");

                        return RedirectToAction("Index", "App");
                    }

                    _logger.LogError($"Registration failed for {model.Username}: ", result.Errors);

                    return View(model);
                }

                return View(model);
            }
            catch (Exception ex)
            {
                _logger.LogError("Database Failure: ", ex);
                return View(model);
            }
        }
Run Code Online (Sandbox Code Playgroud)

我正在学习asp.net,我在这里遇到了一个明显的错误,因为它似乎是一个基本的连接问题,但它没有意义,因为可以使用IdentityDBContext查询数据库,但不能通过UserManager查询在我的理解中使用IdentityDBContext连接.

Tse*_*eng 6

不要使用MySql.Data.EntityFrameworkCore-7.0.7-m61提供者并使用其他东西.Oracle设法在每个预发布版本中使自己难堪.

在这个版本中,他们设法制造了如此困难的软件包,它无法使用,因为该提供商似乎在每次查询后关闭它的连接.请改用Pomelo.EntityFrameworkCore.MySql1.1.0(或等待Oracles提供商的下一个版本).Oracle在使用当前提供商版本支持ADO.NET/EF方面从未发挥过强大的作用

更好的是,使用PostgreSQL或SqlServer代替.