Click here to Skip to main content
11,647,828 members (61,529 online)
Rate this: bad
Please Sign up or sign in to vote.

I am facing following error "Transaction (Process ID 133) was deadlocked on lock | communication buffer resources with another process and has been chosen as the deadlock victim. Rerun the transaction."

Scenario :
I am using "parallel for each" to do "bulk insert during same time some other thread tries to read data from the same table and i get dead lock error.

Please let me know how to solve it.
Posted 24-Dec-12 0:19am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Hi, one of the possible variants is to execute each action in Transaction scope, for example:

Parallel.ForEach(MyIEnumerableSource, insertAction);
static void insertAction(EntityItem item)
using (TransactionScope scope = new TransactionScope(
     Required, new TransactionOptions() {IsolationLevel = ReadCommitted))
    scope.Complete ();
Turbo_23 at 24-Dec-12 6:56am
Hi Oleksandr thanks for your reply, I am getting error when another thread tries to read same table but some other data of the table.
Oleksandr Kulchytskyi at 24-Dec-12 7:07am
Sorry, obviously i inattentively read your question...
Turbo_23 at 24-Dec-12 7:16am
hi,do you know how to solve this issue.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2


a) Select statement in sql server locks the table to avoid deadlock issue use with(nolock) in sql statement.

b) If no index is present on table then delete statement locks the whole table to avoid this create an index.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 500
1 F-ES Sitecore 410
2 DamithSL 290
3 CPallini 290
4 OriginalGriff 277
0 OriginalGriff 1,342
1 994
2 DamithSL 971
3 Sergey Alexandrovich Kryukov 873
4 CPallini 795

Advertise | Privacy | Mobile
Web03 | 2.8.150804.4 | Last Updated 1 Jan 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100