You must Sign In to post a response.
  • Category: LINQ

    Concurrency Control for inserting records based on previous transaction

    I am having a situation in which i have to make the entries from TableA to TableB such that i need to counter-balance the entries. For example: TableA ID Name 1 A 2 B 3 C if no entries in TableB of Table for any user,i will add entries in TableA for User1 As
    <pre>
    ID TableA_ID UserID
    1 1 1
    2 2 1
    3 3 1
    </pre>
    For anther user say User2, i need to check for the entries of lastUser and find out which entry made first. Entry which made first will be made at last for next user. As
    <pre>
    ID TableA_ID UserID
    1 1 1
    2 2 1
    3 3 1
    4 2 2
    5 3 2
    6 1 2
    </pre>
    Similiar for next user enteries will be
    <pre>
    7 3 3
    8 1 3
    9 2 3
    </pre>
    Problem here is that all users may request at the same time and i need to implement locking mechanism to handle it. For any user's request, i need to find the entries for last user. The table must be locked until user makes entries in tableB. In Short i want to control the concurrency. Please suggest how to implement it. It would be better if it does not effect the entries from TableC to TableB.
  • #752044
    Hi,

    Use With NoLock statement to lock the table while accessed by some other person.

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/

  • #752054
    Hello Naveensanagasetti Thanks for reply.

    I am using linq. Please suggest how to proceed.

    I found one solution on that link:-http://www.mstecharticles.com/2012/02/sql-2005-understanding-shared-lock-and.html

    Dont know how to proceed in Linq.

  • #753318
    in order to control concurrency best way is to implement transactions in sqlserver. transactions take care of ACID properties and make sure that the data is commited successfully or rolled back due to failure.
    Miss. Jain
    Microsoft Certified Technology Specialist in .Net


  • Sign In to post your comments