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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:52:38+00:00 2026-06-11T20:52:38+00:00

I am trying to identify the reason of deadlock using SQL Server Profiler. Here’s

  • 0

I am trying to identify the reason of deadlock using SQL Server Profiler.
Here’s the deadlock graph:
Deadlock graph
Both statements are inserts followed by select scope_identity();
Actually a have 2 concurrent processes that repeatedly do insert-select_identity in a cycle.

What would i expect is that insert takes exclusive lock over the clustered index and select takes a shared lock of the non-clustered index, and then they wait for each other to release their respective indeces.

What i see is that both processes wait for the same resource to be released – the clustered index. How can this be? The particular recourse should belong either to one process or to another. What do i miss here?
thanks to all in advance.

Edited: yes, isolation level is Serializible.
PS: probably, my assumption about the shared lock on non-clustered index was wrong as far as my select does not contain a where statement

Edit2:
here is the part of xml:

 <resource-list>
   <keylock hobtid="72057594148028416" dbid="29" objectname="<confidential>" indexname="PK_WP_Inbound_StockTransactionLine" id="lock9641700" mode="RangeS-S" associatedObjectId="72057594148028416">
    <owner-list>
     <owner id="process8e09288" mode="RangeS-S"/>
    </owner-list>
    <waiter-list>
     <waiter id="process991ce08" mode="RangeI-N" requestType="convert"/>
    </waiter-list>
   </keylock>
   <keylock hobtid="72057594148028416" dbid="29" objectname="<confidential>" indexname="PK_WP_Inbound_StockTransactionLine" id="lock9641700" mode="RangeS-S" associatedObjectId="72057594148028416">
    <owner-list>
     <owner id="process991ce08" mode="RangeS-S"/>
    </owner-list>
    <waiter-list>
     <waiter id="process8e09288" mode="RangeI-N" requestType="convert"/>
    </waiter-list>
   </keylock>
  </resource-list>

According to this, i thinks that it is Range scans caused by SERIALIZABLE isolation (googled that). But still, i don’t understand how does this happen and what is the recommended remedy.

  • 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-06-11T20:52:39+00:00Added an answer on June 11, 2026 at 8:52 pm

    Consider following code being called from two parallel transactions(T1 and T2) accessing same record.

    Read LastRow
    Insert AtLastRow
    

    Lets say context switch happens at Read. So sequence of operations is

    T1 Read LastRow
    T2 Read LastRow
    T2 Insert AtLastRow // This will wait for T1 to finish.
    T1 Insert AtLastRow // This will wait for T2 to finish. Hence deadlock!
    

    Above read will take Range S-S lock. Insert at last also needs Range I-N which is not compatable with existing Range S-S lock held by other transactions. Hence it waits.

    There can be multiple ways to solve this problem.

    1. Use read committed as overall isolation level and not serializable.
      This will prevent taking Range locks.
    2. Read with update lock (UPDLOCK). This will take exclusive update
      lock in 1st place. Hence other transaction will wait at Read itself.
    3. Avoid the read and insert/update pattern. Just straight go ahead
      with insert/update and let it fail.

    Let me know if you have any questions.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to identify SQL INSERTS that occur when a record is viewed
I am trying to identify duplicate serial numbers from the following xml using XPath
Using Delphi XE 2 I've trying to identify the zoom direction to apply the
I was trying to identify the reason behind constants in Java I have learned
I am am trying to construct a database in SQL Server 2008 R2 that
I'm trying to avoid using straight SQL queries in my web app. I looked
I'm trying to parse a XML using Apache Commons JXPath. But for some reason,
I'm trying to identify if this is an IIS issue or a code issue.
I am trying to identify when an action without authorization has been made. Is
I am trying to identify a screen in a multi-monitor setup to save some

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.