Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8329941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T01:57:38+00:00 2026-06-09T01:57:38+00:00

Scenario: A save function first reads the total number of rows from a table

  • 0

Scenario:
A save function first reads the total number of rows from a table in the db.
Based on the number of rows, a unique input value is calculated. This value is included in the row that is then inserted into the same table.

Problem:
Two instances of the same object executes the save function at the same time. Here “same time” is the amount of time that it takes the application to read from and insert a row into the db. So, for example,

  • User A clicks save button >> Reads that there are 3 rows in the table >> Calculates f(3) as a unique input value for the new row >> Prepares the new row to insert into the table …

  • User B clicks save button >> (since User A has not inserted the new row) Reads that there are 3 rows in the table >> Calculates f(3) which is NOT a unique value (ERROR!) >> …

How do I rectify this situation? I am not able to alter the db transaction logic since an abstracted ORM layer is being used unfortunately. I have full control over the code however. Any suggestion will be very helpful.

I have anready tried putting a lock() around the save function, but its not helping somehow.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T01:57:40+00:00Added an answer on June 9, 2026 at 1:57 am

    I ended up leveraging the DB generated ID (auto-increment) to do my calculations. Since, rowcount and ID were out of sync, adjusted the new custom id by adding an integer to the new sequence to match the old sequence.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've met a scenario: save or update some data in a target table by
Scenario I would like to save images with alpha transparency as .png and images
Scenario : I'll try to put an analogy with the loan broker example from
Scenario first :- I'm using Entity Framework to do some queries, to build my
Scenario: There is a website with 700-900 concurrent unique visitors at any given time.
Scenario is.... I have to select a row in datagridview and save those datas
Is it possible to use the Matlab save command inside a function to store
Scenario: I save my drawing with a file name as picture . After a
OK, so I've got this totally rare an unique scenario of a load balanced
Scenario As part of a View case page there should be a function to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.