Store update, insert, or delete statement affected an unexpected number of rows (0).

Roshan Kumar 46 Reputation points
2022-11-17T09:55:23.647+00:00

Hi,
During load testing my application, I am getting this error.
Store update, insert, or delete statement affected an unexpected number of rows (0). Entities may have been modified or deleted since entities were loaded.
Scenario being, I am trying to retrieve bearer token from my web api application for the user by passing username, password, client Id and grant type. (Out of 100 threads around 80 are failing).
Attached images of error and the piece of code where error occured.
Am I missing something. Relatively new to this topic.
Please let me if further details required261369-errorauth.png261394-erroroauth.png

Azure SQL Database
ASP.NET API
ASP.NET API
ASP.NET: A set of technologies in the .NET Framework for building web applications and XML web services.API: A software intermediary that allows two applications to interact with each other.
338 questions
0 comments No comments
{count} votes

Accepted answer
  1. ShaktiSingh-MSFT 15,321 Reputation points
    2022-11-17T10:37:52.253+00:00

    Hi @Roshan Kumar ,

    Welcome to Microsoft Q&A platform and thanks for using Azure Services.

    As I understand from the question, Store update, insert, or delete statement affected an unexpected number of rows (0).

    The exception means that between time when you fetched data from database and modified it, your data had been changed.

    Please refer to Saving Changes and Managing Concurrency for more details.

    You can try use refresh method to fix it.

     try {  
         context.SaveChanges();  
     } catch (OptimisticConcurrencyException) {  
         context.Refresh(RefreshMode.ClientWins, yourentity);  
         context.SaveChanges();  
     }  
    

    More discussions link for this issue which might be useful:

    solution-for-store-update-insert-or-delete-statement-affected-an-unexpected-n
    entity-framework-store-update-insert-or-delete-statement-affected-an-unexpec

    Hope this will help. Please let us know if any further queries.

    ------------------------------

    • Please don't forget to click on 130616-image.png or upvote 130671-image.png button whenever the information provided helps you.
      Original posters help the community find answers faster by identifying the correct answer. Here is how
    • Want a reminder to come back and check responses? Here is how to subscribe to a notification
    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.