Results 1 to 5 of 5
  1. #1
    Join Date
    Sep 2004
    Posts
    10

    Unanswered: row locking with asp.net

    i'm currently make a web application using asp.net and oracle 9i.
    i need to make a record/row lock while a user updating the record. how can i do this??

    this is what i want to do:
    1. user A select a record and click edit button, and start editing
    2. at the same time, user B click edit button and selecting the same record with user A too. because user A is still editing so user B get a message "Another user still editing this record".
    3. user A finished editing, and user B click edit button again and now he can edit the row.

    anybody can help me with this??

    thx,


    hongcien

  2. #2
    Join Date
    Aug 2003
    Location
    Where the Surf Meets the Turf @Del Mar, CA
    Posts
    7,776
    Provided Answers: 1
    You can lead some folks to knowledge, but you can not make them think.
    The average person thinks he's above average!
    For most folks, they don't know, what they don't know.
    Good judgement comes from experience. Experience comes from bad judgement.

  3. #3
    Join Date
    Sep 2002
    Location
    UK
    Posts
    5,171
    Provided Answers: 1
    Web-based applications can't hold locks between page refreshes - they don't even remain connected to the database, they re-connect each time. So conventional "pessimistic" locking is out. The usual approach used in "optimistic" locking, whereby no locks are held (of course, for the reason just given), but instead when attempting to perform the update we check whether the record we are updating has been changed by another user since we selected it. This can be done in a variety of ways, including simply comparing the value of every column selected with its current value, e.g.

    update emp
    set deptno = v_new_deptno, ename = v_new_ename, hiredate = v_new_hiredate
    where empno = v_empno
    and deptno = v_old_deptno
    and ename = v_old_ename
    and hiredate = v_old_hiredate;

    If the update updates 0 rows (SQL%ROWCOUNT = 0) then someone else changed at, so you "lose".

    You may be tempted to add a "being_edited_by_user" column to each table as a way of "rolling your own" crude locking mechanism - but really, you don't want to go down that route! You will end up with dozens of records apparently "locked" forever.

  4. #4
    Join Date
    Sep 2004
    Posts
    10
    thx for your replies.
    your reason looks good to me so i better forget about locking huh?
    i'll do that.

    thanks for you help.

  5. #5
    Join Date
    Dec 2010
    Location
    BHOPAL(India)
    Posts
    1

    ASP.Net optimistic and pessimistic record locking

    See a complete working example at

    Locking in ASP.Net (VB.Net) with Oracle database- Practical demonstration

    This uses ASP.NET(VB.NET) with record locking on Oracle Database

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •