SQL SERVER – Fix : Error 1205 : Transaction (Process ID) was deadlocked on resources with another process and has been chosen as the deadlock victim. Rerun the transaction

Fix : Error 1205 : Transaction (Process ID) was deadlocked on resources with another process and has been chosen as the deadlock victim. Rerun the transaction.

Deadlock occurs when two users have locks on separate objects and each user wants a lock on the other’s object. When this happens, SQL Server ends the deadlock by automatically choosing one and aborting the process, allowing the other process to continue. The aborted transaction is rolled back and an error message is sent to the user of the aborted process. Generally, the transaction that requires the least amount of overhead to rollback is the transaction that is aborted.

Fix/Workaround/Solution:
Deadlock priority can be set by user. In other words, user can choose which process should stop to allow other process to continue. SQL Server automatically chooses the process to terminate which is running completes the circular chain of locks. Sometime, it chooses the process which is running the for shorter period then other process.

To reduce the chance of a deadlock:

  • Minimize the size of transaction and transaction times.
  • Always access server objects in the same order each time in application.
  • Avoid cursors, while loops, or process which requires user input while it is running.
  • Reduce lock time in application.
  • Use query hints to prevent locking if possible (NoLock, RowLock)
  • Select deadlock victim by using SET DEADLOCK_PRIORITY.

SQL SERVER 2005 has new priority HIGH as well as numeric-priority.

SQL SERVER 2005 Syntax
SET DEADLOCK_PRIORITY { LOW | NORMAL | HIGH | <numeric-priority> | @deadlock_var | @deadlock_intvar }
<numeric-priority> ::= { -10 | -9 | -8 | … | 0 | … | 8 | 9 | 10 }
Example:
The following example sets the deadlock priority to NORMAL.
SET DEADLOCK_PRIORITY NORMAL;
GO
Reference : Pinal Dave (https://blog.sqlauthority.com)

SQL Error Messages, SQL Scripts, SQL Server
Previous Post
SQL SERVER – Fix: Error 130: Cannot perform an aggregate function on an expression containing an aggregate or a subquery
Next Post
SQL SERVER – Disable Index – Enable Index – ALTER Index

Related Posts

94 Comments. Leave new

  • I have a merge replication environment with one host is
    publisher/distributor and one subscriber. The merge uses continuous replication.

    My MSSQL’s are 2000SP4.

    Error Message:

    The process could not enumerate changes at the ‘Publisher’.
    (Source: Merge Replication Provider (Agent); Error number: -2147200999)
    ——————————————————————————-
    Transaction (Process ID 70) was deadlocked on lock resources with another
    process and has been chosen as the deadlock victim. Rerun the transaction.
    (Source: SERVA_SQL (Data source); Error number: 1205)

    Please advise on the above case.

    sai.

    Reply
  • can we set nolock or rowlock while inserting values as well

    Reply
  • Hi
    But How can I solve this problem?
    blz
    :(

    Reply
  • OLE DB error: OLE DB or ODBC error: Transaction (Process ID 477) was deadlocked on lock resources with another process and has been chosen as the deadlock victim. Rerun the transaction.; 40001.

    Please provide me ans

    Reply
  • Sravan Purumala
    March 22, 2011 9:19 pm

    I have using sql server 2008 R2 Enterprise Edition.

    in one stored procedure ,i am updating on table A only it won’t touch other object and it working fine from past 3 years.
    but suddenly we are getting below error

    Transaction (Process ID 290) was deadlocked on lock | communication buffer resources with another process and has been chosen as the deadlock victim. Rerun the transaction.

    here our code touch only on object A nothing else and the error says lock on some communication buffer.

    please help me it is problem of objects or memory

    Reply
  • I have finally come to the conclusion that this error simply means you are short of resources on the server. I saw that whereas the server usually used 1.6GB for the SQLServer process this had dropped to 0.7. I re-booted the server and the problem went away. I am keeping a much closer eye on system resources now.

    Reply
  • We have some issue with deadlock , coz in a single transaction we r calling around 10 sps.due to that when multiple users try to do the same process,it gets locked.We have used NoLock during the selection.Can we used nested transaction for this?. Could you please give any suggestion for this.

    Reply
  • chetan patel
    June 23, 2011 2:04 pm

    Transaction (Process ID 103) was deadlocked on lock resources with another process and has been chosen as the deadlock victim. Rerun the transaction.

    i have run this command :SET DEADLOCK_PRIORITY NORMAL but still it is given error.

    please help me about this problem.

    Reply
  • Could the “1205” be a result of indexes during INSERT. We have 2 ETL processes, running in parallel that insert into the same table (no issues with duplication). When we originally created the table we did not have any indexes. The parallel ETL processes did not have any problems. After creating the indexes, whenever we ran the processes, we began encountering the “1205” issue. We have other similar parallel processes with other tables (with indexes) that don’t encounter the “1205” but this may be due to the volume of inserts.

    Reply
  • Hi
    I have also received same kind of error as Query Exception: Transaction (Process ID 112) was deadlocked on lock | communication buffer resources with another process and has been chosen as the deadlock victim. Rerun the transaction . We are using a procedure which can be called in the page when many users might be browsing at that time , we are seeing this error in the event logs , i have used deadlock priority to normal but still the issue exists . If any possible solution please let me know . We have indexes on the related tables also accordingly .This issue is using so much of resources that is causing serious errors further after continuous deadlocks happens. thanks in advance.

    Reply
  • As I have said before this error is telling you that you are short of resources and is not a simple locking problem.
    Look at intermediate tuple sizes or other processes running at the same time. Use worst query reports to find the issue or is it that your server wont cope with the number of concurrent sessions?

    Reply
    • Hi! This error happend in my application last week, but I don’t use transactions in this routine code.
      What can it be? Problem in the server? Can anybody help me?

      I don’t know what to say to my customer, I think it’s some problem there, not in my program.

      Thank you!
      Fabiano – Brazil.

      Reply
      • Can you make sure that there are no trasactions used in the code? Also this can happen in other cases like explicit locking, memory issue, etc

      • Yes, our application doesn’t have transactions envolving this table locked. I think is memory issue, we don’t have explicit lockings, so there’s no another explication…

        Thanks!

  • If deadlock happen what we should we do on the workstations? can anyone please advise? I need some guidance to resolve this issue.

    Reply
  • Narendran (@MyNaren89)
    September 30, 2011 9:52 am

    Am also getting the same problem in SQL SERVER 2005, but each time the PROCESS ID is differ.

    Transaction (PROCESS ID 86) WAS DEADLOCKED ON LOCK RESOURCES WITH ANOTHER PROCESS AND HAS BEEN CHOSEN AS THE DEADLOCK VICTIM. RERUN THE TRANSACTION

    Could you please let me know how to fix this resolve this problem this time as well as to knock out this problem in my everynew project.

    Regards,
    Narendran,
    Tweet me at @MyNaren89.
    [phone removed]

    Reply
  • Hi !!
    We are facing Deallocks while calling 2 sps in our system from last 2 3 months …the sps have insert, update queries on a set of tables … First time when we got the deadlock, we solved the issue adding NoLock to a SELECT query which was causing the deadlock.. afterwords we started getting deadlocks on another table to which we add Primary Key.. now again the deadlock is appearing on another table .. We cant go and add PKs or NoLocks on every table .. but need some solution.. can anybody help ??

    Reply
  • Selvaelango Narayanasamy
    November 9, 2011 1:01 pm

    hi,

    i have an update query with the below structure, and i got “Transaction was deadlocked” error how do i resolve, the main concept of the query is i am updating one table values to another table value ( not taking long time to execute)

    UPDATE tableA SET
    tableA.emp_imageURL = tableB.emp_imageURL
    FROM
    (select emp_id,emp_imageURL from Attendance_Entry WITH (NOLOCK) where ident_id=’7767′ ) as tableA
    RIGHT JOIN
    (select emp_id,emp_imageURL=MIN(emp_imageURL) from Permanant_Emp_Details WITH (NOLOCK)
    where emp_id in (select distinct emp_id from Attendance_Entry WITH (NOLOCK) where ident_id=’7767′)
    group by emp_id)
    AS tableB
    ON (tableA.emp_id = tableB.emp_id)

    Reply
    • UPDATE tableA SET
      tableA.emp_imageURL = tableB.emp_imageURL
      FROM
      (select emp_id,emp_imageURL from Attendance_Entry WITH (NOLOCK) where ident_id=’7767′ ) as tableA
      RIGHT JOIN
      (select emp_id,emp_imageURL=MIN(emp_imageURL) from Permanant_Emp_Details WITH (NOLOCK)
      where emp_id in (select distinct emp_id from Attendance_Entry WITH (NOLOCK) where ident_id=’7767′)
      group by emp_id)
      AS tableB
      ON (tableA.emp_id = tableB.emp_id)
      FROM tableB with (nolock)

      Reply
  • Hi
    i got “Transaction WAS DEADLOCKED ” in update query with below query structure, the concept of query is i am updating one table values from another table values

    UPDATE tableA SET
    tableA.emp_imageURL = tableB.emp_imageURL
    FROM
    (select emp_id,emp_imageURL from Attendance_Entry WITH (NOLOCK) where ident_id=’7767′ ) as tableA
    RIGHT JOIN
    (select emp_id,emp_imageURL=MIN(emp_imageURL) from Permanant_Emp_Details WITH (NOLOCK)
    where emp_id in (select distinct emp_id from Attendance_Entry WITH (NOLOCK) where ident_id=’7767′)
    group by emp_id)
    AS tableB
    ON (tableA.emp_id = tableB.emp_id)

    Regards,
    Elango

    Reply
  • Hi … I have the below problem
    Transaction (Process ID 55) was deadlocked on lock | communication buffer resources with another process and has been chosen as the deadlock victim. Rerun the transaction. – 0

    do you know how to fix this error?

    thanks

    Reply
  • try tablock ketyword like
    update tableA WITH (TABLOCK) set column1=’test’

    Reply
  • Hello. Our SQL 2008 server is experiencing this deadlock error:

    2011-11-30 10:47:08.71 spid6s Deadlock encountered …. Printing deadlock information
    2011-11-30 10:47:08.71 spid6s Wait-for graph
    2011-11-30 10:47:08.71 spid6s
    2011-11-30 10:47:08.71 spid6s Node:1
    2011-11-30 10:47:08.71 spid6s OBJECT: 2:1824150806:0 CleanCnt:2 Mode:Sch-S Flags: 0x1
    2011-11-30 10:47:08.71 spid6s Grant List 3:
    2011-11-30 10:47:08.71 spid6s Owner:0x00000002CA27ED00 Mode: Sch-S Flg:0x40 Ref:1 Life:00000000 SPID:70 ECID:0 XactLockInfo: 0x000000030A829340
    2011-11-30 10:47:08.71 spid6s Requested by:
    2011-11-30 10:47:08.71 spid6s ResType:LockOwner Stype:’OR’Xdes:0x0000000212C45970 Mode: Sch-M SPID:70 BatchID:0 ECID:0 TaskProxy:(0x00000002F3B8E510) Value:0x4cc23c0 Cost:(-30/0)

    Does anyone have advice on addressing this error? It appears in the error log file every 10 seconds.

    Thanks,
    Tim

    Reply
  • I am Getting same error from application users so like to know how we can reduce the lock time in application level.
    Anyone have idea to solve this error please?

    Reply

Leave a Reply