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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T03:52:55+00:00 2026-05-16T03:52:55+00:00

I have a process that starts a transaction, inserts a record into Table1, and

  • 0

I have a process that starts a transaction, inserts a record into Table1, and then calls a long running web service (up to 30 seconds). If the web service call fails then the insert is rolled back (which is what we want). Here is an example of the insert (it is actually multiple inserts into multiple tables but I am simplifying for this question):

INSERT INTO Table1 (UserId, StatusTypeId) VALUES (@UserId, 1)

I have a second process that queries Table1 from the first step like this:

SELECT TOP 1 * FROM Table1 WHERE StatusTypeId=2

and then updates that row for a user. When process 1 is running, Table1 is locked so process 2 will not complete until process 1 finishes which is a problem because a long delay is introduced while process 1 finishes its web service call.

Process 1 will only ever insert a StatusTypeId of 1 and it is also the only operation that inserts into Table1. Process 2 will only query on StatusTypeId = 2. I want to tell Process 2 to ignore any inserts into Table1 but lock the row that it selects. The default isolation level for Process 2 is waiting on too much but I have a fear that IsolationLevel.ReadUncommitted allows reading of too much dirty data. I do not want two users running Process 2 and then accidentally getting the same row.

Is there a different IsolationLevel to use other than ReadUncommitted that says ignore inserted rows but make sure the select locks the row that is selected?

  • 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-16T03:52:56+00:00Added an answer on May 16, 2026 at 3:52 am

    Regarding the SELECT being blocked by the insert this should be avoidable by providing appropriate indexes.

    Test Table.

    CREATE TABLE Table1
    (
    UserId INT PRIMARY KEY,
    StatusTypeId INT,
    AnotherColumn varchar(50)
    )
    insert into Table1
    SELECT number, (LEN(type)%2)+1, newid()
    FROM master.dbo.spt_values
    where type='p'
    

    Query window one

    BEGIN TRAN
    INSERT INTO Table1 (UserId, StatusTypeId) VALUES (5000, 1)
    WAITFOR DELAY '00:01';
    ROLLBACK
    

    Query window two (Blocks)

    SELECT TOP 1 * 
    FROM Table1 
    WHERE StatusTypeId=2 
    ORDER BY AnotherColumn
    

    But if you retry the test after adding an index it won’t block CREATE NONCLUSTERED INDEX ix ON Table1 (StatusTypeId,AnotherColumn)

    Regarding your locking of rows for Process 2 you can use the following (the READPAST hint will allow 2 concurrent Process 2 transactions to begin processing different rows rather than one blocking the other). You might find this article by Remus Rusanu relevant

    BEGIN TRAN
    
    SELECT TOP 1 * 
    FROM Table1  WITH (UPDLOCK, READPAST)
    WHERE StatusTypeId=2
    ORDER BY AnotherColumn
    
    /*
    Rest of Process Two's code here
    */
    COMMIT
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an application right now that starts a process, then opens a file
I have a PHP process that: starts as root writes to and then closes
I have some code that starts a background process for search in my WPF
I have some code that creates a Process instance and later starts it. There's
I have a process that imports a lot of data (950k rows) using inserts
I have a process that is running as a java daemon on Ubuntu Linux.
I have a C++ file that: starts the matlab engine calls matlab_optimize() (a compiled
In my application I have a form that starts synchronization process and for number
Imagine I have a process that starts several child processes. The parent needs to
I have a transactional grails service which is doing some (long running) processing. While

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.