How to know when a database operation has succeeded

Arnold Layne
Arnold Layne used Ask the Experts™
on
This question needs a little explanation and background

I have  C# asp.net code that talks to a database and I have javascript on the client end. Javascript makes async calls to the backend c# code via a post and waits for results back. On the client code there is a list of items which get altered based on what the backend page returns.

Currently, when I do any db operation, I then query the db again to get the values of all items on the list and return them back to the client. So any addition, update, deletion...causes me to query the db again and return all items rather than just the one that was altered. This assures that the database and what is on the client list is always the same. But this is inefficient for the db to have that second query.

I'm thinking about simply checking for any errors from the db and then just returning a success or fail and then the javascript can update the list based on values it already had from the submission form.

Is there any way that I could KNOW that the db operation definitely succeeded and there is no chance the db will have different data than the client without having to re-query the db again?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Chief Technology Ninja
Distinguished Expert 2018
Commented:
Hi Arnold,

At any given point of time, if some other user logs on to your app and modifies the data then the servers' data and client's data will not be in Sync. Generally, this is handled by adding concurrency tag / stamp in record. (I am assuming you are on .Net Core here) You can get more details here: https://docs.microsoft.com/en-us/aspnet/core/data/ef-mvc/concurrency?view=aspnetcore-3.1

Basically, you will let the user know that while S/he was working on a particular record, it got changed on the server by someone else / some other process.

If there is only one user who can modify this data then you can safely return success/failure from database and handle it in a straight forward manner.

Regards,
Chinmay.
Arnold LayneDeveloper

Author

Commented:
Each user is unique and they will never be performing operations on the same record. Sorry I forgot to mention that
Arnold LayneDeveloper

Author

Commented:
Thank you for the confirmation of what I suspected.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial