Click here to Skip to main content
11,927,006 members (48,928 online)
Rate this:
Please Sign up or sign in to vote.
See more: SQL-Server SQL-Server-2008 , +

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 1: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 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 24-Dec-12 7:07am
Sorry, obviously i inattentively read your question...
Turbo_23 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
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.151126.1 | 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