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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T01:01:37+00:00 2026-05-14T01:01:37+00:00

I have an application (ASP.NET MVC) that uses a Next New method to get

  • 0

I have an application (ASP.NET MVC) that uses a Next New method to get the next new piece of work. The user clicks on a Next New button, and my NHibernate code would go fetch the next piece of work with an Active status. As the number of users has increased, we have seen an issue arise where 2 users can get the same piece of work. This occurs even though I have wrapped my SELECT and UPDATE calls into a transaction.

I also tried setting the transaction to an IsolationLevel of RepeatableRead, but this would just throw a TransactionException when 2 users try to access the data at the same time.

Here is the process I am currently using:

  1. Get the next work object
  2. Update the object to show it is pended and save to the db
  3. Display the work to the user

Here is the code I am currently using:

    using (var txn = _repository.Session.BeginTransaction(IsolationLevel.RepeatableRead))
    {
        try
        {
            newAccount = _repository.FindFirstWithLock(criteria, LockMode.Read);

            newAccount.QueueStatus = pendingStatus;
            _repository.Save(newAccount);    

            txn.Commit();
        }
        catch (Exception)
        {
            txn.Rollback();
            throw;
        }
    }

The criteria is a DetachedCriteria object which just looks for accounts which are active and sorts descending by a date property.

Does anyone have any suggestions on how I could make this work?

  • 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-14T01:01:37+00:00Added an answer on May 14, 2026 at 1:01 am

    Update:

    I solved this problem by sending through a custom T-SQL Statement, locking the current row, and reading past the locked row if one was already locked:

        using (var txn = _accountRepository.Session.BeginTransaction())
        {
            try
            {
    
                updateResult = _accountRepository.Session.CreateSQLQuery(
                    SqlQueries.GetNextQueueItem(orderByClause, strategyId, languageId, tomorrow, userName)).ExecuteUpdate();
                txn.Commit();
            }
            catch (Exception)
            {
                txn.Rollback();
                throw;
            }
        }
    

    The SQL Query looks like this:

    UPDATE       ACCOUNTS 
                SET          QUEUE_STATUS_ID = 2 
                            ,OWNED_BY = '[username]' 
                            ,OWNERSHIP_DATE = GETDATE() 
                FROM        ACCOUNTS   
                WHERE   CUSTOMER_ACCOUNT_ID = 
                                ( 
                                    SELECT      TOP(1) CUSTOMER_ACCOUNT_ID 
                                    FROM        FIT_PAYPAL_ACCOUNTS  WITH(ROWLOCK, READPAST, UPDLOCK) 
                                    WHERE           STRATEGY_ID = 999
                                                AND NEXT_WORK_DATE < '3/1/2010' 
                                                AND STATUS_ID = 0 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an ASP.NET MVC application, when a user clicks on the submit button
I have a simple ASP.NET MVC web application that uses NHibernate with FluentNHibernate's auto
I am using asp.net MVC to develop an application that will have ajax interactions.
I am looking at globalizing an application that I have developed in asp.net mvc.
We have an ASP.NET application that's partly in MVC (the rest of it being
I have an asp.net MVC application that has one section /admin locked down via
I have the requirement to support different Master pages on my application (ASP.NET MVC).
Hi I am developing a simple application based upon ASP.NET MVC. I have altered
I have an ASP.NET MVC-application which I want deployable on both IIS6 and IIS7
I have an asp.net mvc application with a route similar to: routes.MapRoute(Blog, {controller}/{action}/{year}/{month}/{day}/{friendlyName}, new

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.