UserManager CreateAsync 메서드를 사용하여 새 사용자를 만들려고 할 때 다음 오류가 발생합니다. 나는 수정되지 않은 IdentityUser와 IdentityRole을 사용하고있다. 데이터베이스의 데이터로 채워지는 DB 세트가 몇 개 있습니다. 따라서 독서가 문제가되지 않습니다. 글을 쓰는 것만 같습니다.
{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}
나는 사용하고있다;
오류에서 언급 한 102 행은 var result = 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);
}
}
나는 asp.net을 배우고있어 기본 연결 문제 인 것처럼 보이는 명백한 오류가 있지만 데이터베이스가 IdentityManagerontext를 사용하여 쿼리 할 수 있지만 UserManager를 통해 쿼리 할 수는 없다는 점에서 내가 바라는 바에 대한 걸림돌은 분명한 오류입니다. 내 이해에서는 IdentityDBContext 연결을 사용합니다.
MySql.Data.EntityFrameworkCore-7.0.7-m61
공급자를 사용하지 말고 다른 것을 사용하십시오. 오라클은 각 시험판 버전으로 스스로를 당혹스럽게합니다.
이 릴리스에서는 패키지를 너무 세게 제동 할 수 있었기 때문에 공급자가 모든 쿼리 후에 연결을 닫는 것처럼 보이지 않으므로 사용할 수 없습니다. 대신 Pomelo.EntityFrameworkCore.MySql
1.1.0을 사용하십시오 (또는 Oracles 공급자의 다음 릴리스를 기다리는 중입니다). 오라클은 ADO.NET / EEF를 현재 공급자 버전으로 지원하는 데 절대 강하지 않았습니다.
더 좋은 방법은 대신 PostgreSQL 또는 SqlServer를 사용하는 것입니다.