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

  • SEARCH
  • Home
  • 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 160541
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T11:03:12+00:00 2026-05-11T11:03:12+00:00

The problem I have is this: I have a table (just an example) with

  • 0

The problem I have is this:

I have a table (just an example) with the following fields:

ID int Value int 

I have a method called IncreaseByFive() which does the following:

method IncreaseByFive(int ID) {         int value = GetValueFromDB(ID);     value = value + 5;     SaveValueToDB(value, ID);     } 

What I want to avoid is the following situation:

  1. User A calls method and gets the value (currently 5)
  2. User B calls method and gets the value (currently 5)
  3. User A increases value by 5 (now 10)
  4. User B increases value by 5 (now 10)
  5. User A saves value (10)
  6. User B saves value (10)

Now the record has a value of 10 when it should have been 15.

What I want to force is the following:

  1. User A calls method and gets the value (currently 5)
  2. User B calls method but has to wait because A already called it. (Dibs!)
  3. User A increases the value (now 10)
  4. User B is still waiting
  5. User A saves the value (record has value of 10)
  6. User B can now read the value (10)
  7. User B increases the value (15)
  8. User B saves the value

Now the record has a value of 15, which is the outcome I’m looking for.

I’ve solved this problem in the past using a static class and putting a lock on a static object created within the constructor of that class, thus funneling all the work through one static method, which forces other calls to wait in line. I’m afraid however that this isn’t scalable.

I also think that the the highest isolation level (serializable) for a transaction won’t do the trick either because it will allow the read in step 2 of the unwanted example above.

I suppose another solution would be to create my own lock table and record the locks there, but that seems like it shouldn’t be neccessary.

I’m developing this project with C# (3.5) and SQL server 2008.

What does the hive mind think?

  • 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. 2026-05-11T11:03:12+00:00Added an answer on May 11, 2026 at 11:03 am

    Maybe I’m overunderthinking this, but wouldn’t you just wrap the entire logic block..

    • read value
    • write value

    in a database transaction of the appropriate level?

    SET TRANSACTION ISOLATION LEVEL     { READ UNCOMMITTED     | READ COMMITTED     | REPEATABLE READ     | SNAPSHOT     | SERIALIZABLE     } [ ; ] 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 119k
  • Answers 119k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Pai eu cred ca pagina 10690 din grupul primar este… May 11, 2026 at 11:41 pm
  • Editorial Team
    Editorial Team added an answer If you're using this cscope mode it looks like you… May 11, 2026 at 11:41 pm
  • Editorial Team
    Editorial Team added an answer // create the Person object, case sensitive var personObj =… May 11, 2026 at 11:41 pm

Related Questions

Here is the problem I am trying to solve. I have a table where
Is there a way to get struts 2 (using tiles) to build the whole
I am using polymorphic associations to track Comments in my project. All very straight
I will try and explain exactly what I want to achieve first. Imagine two

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.