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 7682941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:40:59+00:00 2026-05-31T18:40:59+00:00

I have a C# application that is used by about a dozen employees simultaneously.

  • 0

I have a C# application that is used by about a dozen employees simultaneously. It simply SELECTs the top record from a SQL Server 2005 table, DELETE it, then displays the data on a form.
As soon as the record is selected it needs to be deleted so 2 ppl don’t grab and work on the same record.
Fairly Straight Forward…

I found a suggestion a while ago (cant find the site i got it from, sorry) to do a SELECT and DELETE in the same statement and execute a SqlCommand.ExecuteReader() with this “compound” statement:

SELECT TOP 1 * 
FROM Call_Table 
WHERE Call_Table.hold_call_till <= GetDate() 
ORDER BY Call_Table.attempts ASC, Call_Table.custno ASC;
DELETE 
FROM Call_Table
WHERE Call_Table.custno = (SELECT TOP 1 Call_Table.custno 
                           FROM Call_Table 
                           WHERE Call_Table.hold_call_till <= GetDate() 
                           ORDER BY Call_Table.attempts ASC, Call_Table.custno ASC);

Its been working quite well so far, but i feel like i’ve just been lucky. We’re hiring about 5 new ppl, and i would like to totally sure this will continue to work.

Im interested to hear the opinion of more seasoned vets in this area.

Should I stick with the “If its not broken, dont fix it” approach?? Or should I step up my game and use some kind of record_locks or stored procs??

Any suggestions will be openly accepted. I can supply more info about the table or C# application if necessary.

  • 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-05-31T18:41:00+00:00Added an answer on May 31, 2026 at 6:41 pm

    I would suggest using some sort of optimistic concurrency control instead. Do not delete the record, but instead store a timestamp (or some other versioning technique) which will be grabbed on select. Then, if the user edits something you can check to make sure the timestamp has not changed. If it has, then prompt the user and reload the new data. If it has not, then save the data, and update the timestamp so that anybody else with the data will not overwrite your changes.

    Microsoft’s article on optimistic concurrency

    Here is my version of a graphical example (using a numbering system instead of timestamps for the versioning)

    Name|PhoneNum|Version
    Joe |123-1234|1
    
    • UserA and UserB pull up Joe’s data in your UI

    • UserA modifies and saves Joe

    Now the table looks like this:

    Name|PhoneNum|Version
    Joe |555-5555|2
    
    • UserB modifies the Version 1 of Joe’s data and saves. The save sees that the Version is now 2 and prompts UserB that the data has changed.

    UPDATE

    You have two options if the row cannot be accessed while the User is reading it.

    • You can do what you are already doing, but you do not need the select…delete due to OUTPUT (as suggested above already). With this, you can delete and get the value.

    Code:

    DECLARE @CallInfo TABLE (/*Call_Table Schema*/)
    
    DELETE Call_Table
    OUTPUT DELETED.* INTO @CallInfo 
    WHERE Call_Table.custno = (SELECT TOP 1 Call_Table.custno 
                           FROM Call_Table 
                           WHERE Call_Table.hold_call_till <= GetDate() 
                           ORDER BY Call_Table.attempts ASC, Call_Table.custno ASC)
    
    --The @CallInfo will have the info that you just deleted, so pass that back to the UI
    SELECT * FROM @CallInfo
    
    • You can add a lock column (using the user id of the person locking) that you update right before you select the data. The only thing you then need to worry about it if the user crashes or does something where they do not reset the lock. I have used this system in the past, but the complexity might not be worth it if most of the time the data is deleted. I find this more useful if you need to simply update data. You can add logic that says, if the same user tries to get the data again, then let them since it was probably a crash. Otherwise, you then need to create an unlocking system.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have an in house winform application that is used by about 20 users
I have a server application that spins up and monitors about 8 separate processes
I have an application that used Macro. In this macro I would like to
Say I have an application that used an ORM (I am thinking of nHibernate
I have an application that is used on several hundred computers across the company
I have an existing 32-bit ASP.NET application that used 32-bit unmanaged DLLs. If I
I have a small lightweight application that is used as part of a larger
I have an application that was originally written in Borland C++ and used a
We have a Struts 2 web application that's used by pretty much every employee
The problem: we have one application that has a portion which is used by

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.