Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
Hi,
 
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
Adi_1.9K
Rate this: bad
good
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))
  {   
try{
      ExecuteInsertQuery(item);
    scope.Complete ();
}
catch{scope.Rollback();}
}
  Permalink  
Comments
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
good
Please Sign up or sign in to vote.

Solution 2

hi,
 
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.
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 406
1 Marcin Kozub 225
2 Sergey Alexandrovich Kryukov 205
3 Raul Iloc 170
4 Maciej Los 164
0 OriginalGriff 8,289
1 Sergey Alexandrovich Kryukov 7,407
2 DamithSL 5,624
3 Maciej Los 4,989
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web01 | 2.8.1411023.1 | Last Updated 1 Jan 2013
Copyright © CodeProject, 1999-2014
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