Base solution for your next web application
Open Closed

ASP.NET Core / Angular 2 Login Error / MySQL #3528


User avatar
0
karimgarza created

Hi,

I am getting the following error when I log in for the first time to the application and the flag ShouldChangePasswordOnNextLogin is true

INFO  2017-07-10 22:11:10,564 [3    ] ore.Mvc.Internal.ControllerActionInvoker - Executing action method Airforce.AFWIN.Web.Controllers.TokenAuthController.Authenticate (Airforce.AFWIN.Web.Core) with arguments (Airforce.AFWIN.Web.Models.TokenAuth.AuthenticateModel) - ModelState is Valid
DEBUG 2017-07-10 22:11:14,171 [3    ] ore.Mvc.Internal.ControllerActionInvoker - Executed action method Airforce.AFWIN.Web.Controllers.TokenAuthController.Authenticate (Airforce.AFWIN.Web.Core), returned result Microsoft.AspNetCore.Mvc.ObjectResult.
ERROR 2017-07-10 22:11:14,215 [3    ] Mvc.ExceptionHandling.AbpExceptionFilter - Database operation expected to affect 1 row(s) but actually affected 0 row(s). Data may have been modified or deleted since entities were loaded. See http://go.microsoft.com/fwlink/?LinkId=527962 for information on understanding and handling optimistic concurrency exceptions.
Abp.Domain.Uow.AbpDbConcurrencyException: Database operation expected to affect 1 row(s) but actually affected 0 row(s). Data may have been modified or deleted since entities were loaded. See http://go.microsoft.com/fwlink/?LinkId=527962 for information on understanding and handling optimistic concurrency exceptions. ---> Microsoft.EntityFrameworkCore.DbUpdateConcurrencyException: Database operation expected to affect 1 row(s) but actually affected 0 row(s). Data may have been modified or deleted since entities were loaded. See http://go.microsoft.com/fwlink/?LinkId=527962 for information on understanding and handling optimistic concurrency exceptions.
   at Microsoft.EntityFrameworkCore.Update.AffectedCountModificationCommandBatch.ThrowAggregateUpdateConcurrencyException(Int32 commandIndex, Int32 expectedRowsAffected, Int32 rowsAffected)
   at Microsoft.EntityFrameworkCore.Update.ReaderModificationCommandBatch.Execute(IRelationalConnection connection)
   at Microsoft.EntityFrameworkCore.Update.Internal.BatchExecutor.Execute(Tuple`2 parameters)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChanges(IReadOnlyList`1 entriesToSave)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChanges(Boolean acceptAllChangesOnSuccess)
   at Microsoft.EntityFrameworkCore.DbContext.SaveChanges(Boolean acceptAllChangesOnSuccess)
   at Abp.EntityFrameworkCore.AbpDbContext.SaveChanges()
   --- End of inner exception stack trace ---
   at Abp.EntityFrameworkCore.AbpDbContext.SaveChanges()
   at Abp.EntityFrameworkCore.Uow.EfCoreUnitOfWork.SaveChanges()
   at Abp.EntityFrameworkCore.Uow.EfCoreUnitOfWork.CompleteUow()
   at Abp.Domain.Uow.UnitOfWorkBase.Complete()
   at Abp.Domain.Uow.UnitOfWorkInterceptor.PerformSyncUow(IInvocation invocation, UnitOfWorkOptions options)
   at Castle.DynamicProxy.AbstractInvocation.Proceed()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Abp.Events.Bus.EventBus.Trigger(Type eventType, Object eventSource, IEventData eventData)
   at Abp.Events.Bus.EventBus.TriggerHandlingException(Type eventType, Object eventSource, IEventData eventData, List`1 exceptions)
   at Abp.Events.Bus.EventBus.Trigger(Type eventType, Object eventSource, IEventData eventData)
   at Abp.Events.Bus.EventBus.TriggerHandlingException(Type eventType, Object eventSource, IEventData eventData, List`1 exceptions)
   at Abp.Events.Bus.EventBus.Trigger(Type eventType, Object eventSource, IEventData eventData)
   at System.EventHandler.Invoke(Object sender, EventArgs e)
   at Abp.Domain.Uow.UnitOfWorkBase.OnCompleted()
   at Abp.Domain.Uow.UnitOfWorkBase.<CompleteAsync>d__56.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 Abp.AspNetCore.Mvc.Uow.AbpUowActionFilter.<OnActionExecutionAsync>d__3.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.Mvc.Internal.ControllerActionInvoker.<InvokeNextActionFilterAsync>d__25.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext context)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeNextExceptionFilterAsync>d__24.MoveNext()
DEBUG 2017-07-10 22:11:14,230 [3    ] ore.Mvc.Internal.ControllerActionInvoker - Request was short circuited at exception filter 'Abp.AspNetCore.Mvc.ExceptionHandling.AbpExceptionFilter'.
DEBUG 2017-07-10 22:11:14,230 [3    ] etCore.Mvc.Internal.ObjectResultExecutor - Could not find an output formatter based on content negotiation. Accepted types were (application/json; charset=UTF-8)
DEBUG 2017-07-10 22:11:14,230 [3    ] etCore.Mvc.Internal.ObjectResultExecutor - Selected output formatter 'Microsoft.AspNetCore.Mvc.Formatters.JsonOutputFormatter' and content type 'application/json' to write the response.
INFO  2017-07-10 22:11:14,230 [3    ] etCore.Mvc.Internal.ObjectResultExecutor - Executing ObjectResult, writing value Microsoft.AspNetCore.Mvc.ControllerContext.

Do you guys have any ideas as to why I am getting this error ?

The error does not happen if the ShouldChangePasswordOnNextLogin is set to false.

Thank you in advance,


9 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Do you use Sql Server ?

    Thanks.

  • User Avatar
    0
    karimgarza created

    I'm using MySQL with this provider

    Devart.Data.MySql.EFCore 8.9.931

    Devart.Data.MySql.EFCore.Design 8.9.931

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Have you deleted migration files and created them from scratch again ? Becasue current migrations are created for MsSql.

    Just delete all migration files including snapshot and recreate migration files using Add-Migration command. Then you can use Update-Database command to create your database again.

    Thanks.

  • User Avatar
    0
    karimgarza created

    Hi,

    Thank you for your reply.

    I created a new project today from your site, changed the application to single tenant, then removed the nuget package for sql server and added the the mysql nuget packagesmentioned in this post, changed the connection string, removed all the migrations, added a new migration updated the database using Update-Database.

    I launched the asp.net core project and it ran (showed the swagger api), then i launched the angular project and I got the following error in the asp.net log when i opened the browser to <a class="postlink" href="http://localhost:4200">http://localhost:4200</a>

    It seems that the angular project was trying to call the following endpoint <a class="postlink" href="http://localhost:22742/AbpUserConfiguration/GetAll">http://localhost:22742/AbpUserConfiguration/GetAll</a> and got back an internal server error

    Abp.AbpException: No language defined!
       at Abp.Localization.MultiTenantLocalizationDictionaryProvider.GetDefaultDictionary()
       at Abp.Localization.Dictionaries.DictionaryBasedLocalizationSource.GetAllStrings(CultureInfo culture, Boolean includeDefaults)
       at Abp.Web.Configuration.AbpUserConfigurationBuilder.GetUserLocalizationConfig()
       at Abp.Web.Configuration.AbpUserConfigurationBuilder.<GetAll>d__13.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 Abp.AspNetCore.Mvc.Controllers.AbpUserConfigurationController.<GetAll>d__2.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.Mvc.Internal.ObjectMethodExecutor.<CastToObject>d__38`1.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.Mvc.Internal.ControllerActionInvoker.&lt;InvokeActionMethodAsync&gt;d__27.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.Mvc.Internal.ControllerActionInvoker.&lt;InvokeNextActionFilterAsync&gt;d__25.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext context)
       at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
       at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.&lt;InvokeNextExceptionFilterAsync&gt;d__24.MoveNext()
    
  • User Avatar
    0
    karimgarza created

    One thing that I noticed is that every time i re-launch the asp.net core application, the table abplanguages ends up with 10 more records. Right now I launched the application 5 times and I have 50 records.

  • User Avatar
    0
    karimgarza created

    It finally works !

    I don't think I know what the problem is other than the application keep trying to re-insert languages upon every re-start, but removing the references to the devart dependencies and changing them for the mysql pomelo ones, removing all of the migrations, creating a new migration, updating the database and running the application works.

    I used the following mysql packages for EF Core

    <a class="postlink" href="https://www.nuget.org/packages/Pomelo.EntityFrameworkCore.MySql/2.0.0-preview2-10046">https://www.nuget.org/packages/Pomelo.E ... iew2-10046</a> <a class="postlink" href="https://www.nuget.org/packages/Pomelo.EntityFrameworkCore.MySql.Design/">https://www.nuget.org/packages/Pomelo.E ... ql.Design/</a>

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @karimgarza,

    It is good that you managed to run your application. In EntityFramework Core, there is no database seed yet, so we insert seed data on application start of Host project. But, anyway, it should not insert duplicate records to languages table.

    So this happens when you disabled multi tenancy, right ? I am asking because I will create a bug report about this.

    Thanks.

  • User Avatar
    0
    karimgarza created

    Hi,

    This happens when multi-tenancy is disabled and using the following ef providers

    Devart.Data.MySql.EFCore 8.9.931 Devart.Data.MySql.EFCore.Design 8.9.931

    But it does not happen with the Pomelo MySQL EF providers

    There must be something that the Devart EFCore components do not implement and the Pomelo ones do.

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @karimgarza,

    Thanks for the additional informations. As far as I searched, the best MySql provider for EntityFramework Core is Pomelo. Others are not yet so mature, so you can continue with it.

    Thanks.