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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:16:18+00:00 2026-05-27T21:16:18+00:00

Question on locking scope in SQL Server (SQL Azure to be precise). Scenario A

  • 0

Question on locking scope in SQL Server (SQL Azure to be precise).

Scenario

A bunch of records are selected using a select statements.
We loop through the records
Each record is updated within a transactionscope –
(each record is independent of the other and there is no need for a table lock)

Am I right in assuming that the above would result in a row level lock of just that particular record row?

Framing the question within the context of a concrete example.
In the below example would each item in itemsToMove be locked one at a time?

var itemsToMove  = ObjectContext.Where(emp => emp.ExpirationDate < DateTime.Now)                        
foreach(Item expiredItem in itemsToMove)
{               
    bool tSuccess = false;
    using (TransactionScope transaction = new TransactionScope())
    {
        try
        {               
            //We push this to another table. In this case Azure Storage.                    
            bool bSuccess = PushToBackup();             
            if(bSuccess)
            {
                ObjectContext.DeleteObject(expiredItem);
            }
            else 
            {
                //throw an exception or return 
                return false;
            }
            ObjectContext.SaveChanges();

            transaction.Complete();
            tSuccess = true;
        }
        catch (Exception e)
        {
            return cResults;
        }       
    }
}
if (tSuccess)
{
    ObjectContext.AcceptAllChanges();
}
  • 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-27T21:16:19+00:00Added an answer on May 27, 2026 at 9:16 pm

    Provided that there isn’t any outer / wrapper transaction calling your code, each call to transaction.Complete() should commit and release any locks.

    Just a couple of quick caveats

    • SQL will not necessarily default to row level locking – it may use page level or higher locks (recommend that you leave SQL to its own devices, however)
    • Note that the default isolation level of a new TransactionScope() is read serializable. This might be too pessimistic for your scenario.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Seeing various locking related question and (almost) always finding the 'loop because of spurious
I would like to ask couple of questions regarding SQL Server Locking mechanism If
i have some simple SELECT statements and an INSERT wrapped in a using(TransactionScope...) block.
I have a question about locking. This doesn't have to be only about record
This is related to a question I asked here: Thread Locking in Ruby (use
After looking at another question on SO ( Using NaN in C++ ) I
I need an SQL statement that check if one condition is satisfied: SELECT *
Hello wonderful stackoverflowers! I hope this question is within the scope of this site.
This question is even harder today because I haven't had any luck using the
I've alluded to this project before, in this question, but the scope of redesign

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.