Forums - C# Corner

Forum guidelines
Rakesh Singh

Rakesh Singh

  • 1.8k
  • 57
  • 2.4k

Concurrency Issue

Feb 5 2018 2:45 AM
Issue:
 
When Two user tring to insert at same time at same place, then two row are generating for the same row as given below :
 
 
What happening is here, both records came at same time, when first record finish the execute INSERT query and came out then second also come inside the INSERT because when its in there till then first one was not in database so, it understand that its a new record and new row generated.
  1. INSERT INTO MME.ForecastAdjustmentLineItem  
  2. (ForecastVersionId  
  3. ,[CostCollectorId]  
  4. ,AdjustmentDesc  
  5. ,AdjustmentTypeCd  
  6. ,ElementCategoryId  
  7. ,CurrencyCd  
  8. ,AdjustmentAmt  
  9. ,SpeculativeInd  
  10. ,CreateUserId  
  11. ,CreateDttm  
  12. ,UpdateUserId  
  13. ,UpdateDttm  
  14. ,LastUpdateDttm)  
  15. VALUES  
  16. (@ForecastVersionId  
  17. ,@CostCollectorId  
  18. ,@AdjustmentDesc  
  19. ,@AdjustmentTypeCd  
  20. ,@ElementCategoryId  
  21. ,@CurrencyCd  
  22. ,@AdjustmentAmt  
  23. ,0  
  24. ,@CreateUserId  
  25. ,@CreateDttm  
  26. ,@UpdateUserId  
  27. ,@UpdateDttm  
  28. ,@LastUpdateDttm )  
  29. SET @ForecastAdjustmentLineItemId = SCOPE_IDENTITY()  

Answers (2)