CodeSmith Community
Your Code. Your Way. Faster!

Timestamp Concurrency Control

Latest post 11-25-2007 3:27 PM by Miketrix. 16 replies.
  • 01-05-2007 8:59 AM

    • mtutt
    • Top 500 Contributor
    • Joined on 12-12-2006
    • Posts 10
    • Points 230

    Timestamp Concurrency Control

    We're getting ready to develop our first concept piece for a new product using NetTiers, and the issue of concurrency with the Web Controls is our single biggest concern.  There've been a couple of other posts about it, but there hasn't seemed to be a resolution.  Swin had reported that he'd come up with a work around using a modified formUtils class, but I don't see it available as a patch.

    If anyone has an example of what they've done, template hacking, generated code rework, etc. that addresses the issue, we'd love to avoid re-inventing the wheel.

    Thanks,

    Mark

    Filed under: ,
    • Post Points: 35
  • 01-05-2007 9:05 AM In reply to

    • swin
    • Top 10 Contributor
    • Joined on 06-14-2006
    • London, UK
    • Posts 922
    • Points 34,710

    Re: Timestamp Concurrency Control

    Hi Mark,

    I hadn't forgotton about the concurrency issue, its just they haven't been fully tested yet.  I'm happy to post them up but be aware they're still only "beta" code.

    Perhaps you can give them a good testing for meWink 

    hth

    swin 

    ------------------------------------------------- Member of the .NetTiers team -------------------------------------------------
    • Post Points: 35
  • 01-05-2007 9:23 AM In reply to

    • mtutt
    • Top 500 Contributor
    • Joined on 12-12-2006
    • Posts 10
    • Points 230

    Big Smile [:D] Re: Timestamp Concurrency Control

    We'll happily test them to death over the next month, and contribute back any changes...
    • Post Points: 35
  • 01-05-2007 10:09 AM In reply to

    • swin
    • Top 10 Contributor
    • Joined on 06-14-2006
    • London, UK
    • Posts 922
    • Points 34,710

    Re: Timestamp Concurrency Control

    Ok, here you are.

    Attached is a file containing code that needs to be added to your FormUtil.cs  that resides in the web project.

    As I previously posted in another thread, I found that using the entitydatasource (EDS) and strongly typd data source controls (STDS) did not handle concurrency checking when only using a timestamp field.  I think the reason is that the timestamp field is not maintained between postbacks.  Typically you wouldn't put that sort of field on a screen anyhow (it can be done but its a bit messy) so my work around is to do the following:

    1. Use the DataKeyNames of the gridview/formview to store the timestamp value across postbacks.  This doesn't seem to have any adverse affects with regards to what the actual keys are (indeed I've seen a post from a microsoft person suggesting using the datakeynames for a similar purpose).

    2. However, the EDS & STDS need to be passed the timestamp field so it can check whether its changed using the underlying stored proc. So in the gridview/formview update event the timestamp field needs to be moved from the DataKeyNames to the NewValues.

    The above would be enough for NetTiers to raise an exception when a concurrency issue had occurred. But thats not good enough is it?Big Smile

    3. It would be really cool if we automatically give the users feedback on what happened.  So I've also included some methods that try to figure out what went wrong. So far I've added code for checking :

    Concurrency exception (gives a user friendly message),

    SQL exceptions (handles things like connectivity and constraint problems) and

    entity errors (any broken rules messages).

    This feedback is done by creating custom validators for the appropriate controls and assuming you have a validationsummary control on your form you should see appropriate messages.

    All of the above is wrapped up into one neat call (overloads available) which you need to place in your Page_Load method...

    FormUtil.HandleGridView( GridView1, "ConcurrencyTimeStamp" ); // for a gridview (or EntityGridView)

    or

    FormUtil.HandleFormView( FormView1, "ConcurrencyTimeStamp" ); // for FormView

    Where "ConcurrencyTimeStamp" is the name of your timestamp field. 

     

    I hope it works for you. If it does perhaps it could be included in the NetTiers build?

    Enjoy!

    swin 

    PS. Some of the code is based on work done by Meech (I think), but I've beefed it up and adapted it for my own use.

    ------------------------------------------------- Member of the .NetTiers team -------------------------------------------------
    • Post Points: 45
  • 01-05-2007 10:25 AM In reply to

    • mtutt
    • Top 500 Contributor
    • Joined on 12-12-2006
    • Posts 10
    • Points 230

    Re: Timestamp Concurrency Control

    Thank you!  I'll make sure we include test cases for it and let you know how we make out with it.
    • Post Points: 35
  • 01-12-2007 10:22 AM In reply to

    • swin
    • Top 10 Contributor
    • Joined on 06-14-2006
    • London, UK
    • Posts 922
    • Points 34,710

    Re: Timestamp Concurrency Control

    Any news on this?

    swin 

    ------------------------------------------------- Member of the .NetTiers team -------------------------------------------------
    • Post Points: 60
  • 01-16-2007 8:17 AM In reply to

    • mtutt
    • Top 500 Contributor
    • Joined on 12-12-2006
    • Posts 10
    • Points 230

    Re: Timestamp Concurrency Control

    Work is progressing, but we haven't set up a multi-user test environment yet.  Probably another week or two.  I will let you know!
    • Post Points: 5
  • 01-24-2007 10:20 AM In reply to

    • mtutt
    • Top 500 Contributor
    • Joined on 12-12-2006
    • Posts 10
    • Points 230

    Re: Timestamp Concurrency Control

    Swin, check your Inbox for a private message...
    • Post Points: 35
  • 03-13-2007 4:26 AM In reply to

    • bfaassen
    • Not Ranked
    • Joined on 03-07-2007
    • Posts 3
    • Points 75

    Re: Timestamp Concurrency Control

    In our project we need optimistic concurrency control in an ASP.NET application... I am wondering what the current status is of the solution you posted.

    Is this already implemented in the latest templates?

    Thanks in advance

    Barry

     

    • Post Points: 35
  • 03-13-2007 4:36 AM In reply to

    • swin
    • Top 10 Contributor
    • Joined on 06-14-2006
    • London, UK
    • Posts 922
    • Points 34,710

    Re: Timestamp Concurrency Control

    No, you have to apply to your FormUtil class.

    However, I don't think theres any reason why they couldn't be added to the main templates.

    hth

    swin 

    ------------------------------------------------- Member of the .NetTiers team -------------------------------------------------
    • Post Points: 35
  • 11-12-2007 11:26 AM In reply to

    • evolved
    • Top 50 Contributor
    • Joined on 12-27-2004
    • South River, NJ
    • Posts 93
    • Points 1,825

    Re: Timestamp Concurrency Control

    Swin, Is there any particular reason why your contrib didn't get commited?

    http://www.jheidt.com
    ------------------------------
    Member of the .NetTiers team
    http://www.nettiers.com
    ------------------------------

    • Post Points: 35
  • 11-12-2007 1:59 PM In reply to

    • swin
    • Top 10 Contributor
    • Joined on 06-14-2006
    • London, UK
    • Posts 922
    • Points 34,710

    Re: Timestamp Concurrency Control

    yes, laziness....Stick out tongue

    ------------------------------------------------- Member of the .NetTiers team -------------------------------------------------
    • Post Points: 35
  • 11-13-2007 12:23 PM In reply to

    • evolved
    • Top 50 Contributor
    • Joined on 12-27-2004
    • South River, NJ
    • Posts 93
    • Points 1,825

    Re: Timestamp Concurrency Control

    Hrmm, I tried to branch laziness off the trunk, but I still had it in my source when I got the latest. 

    http://www.jheidt.com
    ------------------------------
    Member of the .NetTiers team
    http://www.nettiers.com
    ------------------------------

    • Post Points: 35
  • 11-24-2007 7:48 AM In reply to

    • nox
    • Not Ranked
    • Joined on 11-29-2004
    • Posts 2
    • Points 40

    Re: Timestamp Concurrency Control

    Hi all, I'm pretty new to netTiers and need concurrence control if I'm going to use it in a production environment.

    I implemented the code as proposed by swin, which seems ok. Except, when I try to update a row that already has been updated by another user, it still gets update normally.

    I never get the DBConcurrencyException

    I have tested this with enableEntityTracking on and off, but the result is always the same. It always updates the record, even if it has changed in the meantime.

    Anyone?

    • Post Points: 5
  • 11-24-2007 1:50 PM In reply to

    • nox
    • Not Ranked
    • Joined on 11-29-2004
    • Posts 2
    • Points 40

    Re: Timestamp Concurrency Control

    Forget my last message, swin's solutions works fine !!! I had mistyped the name of my timestamp field. In the database I use "CC" en in the code I have to use "Cc", but I used "CC", silly.... So, maybe we could use some strong typed stuff here, so stupid people like wont mix up filed names. :-) anyway, thanks for your solution swin, I hope it gets into the templates.
    • Post Points: 35
Page 1 of 2 (17 items) 1 2 Next > | RSS
Copyright © 2008 CodeSmith Tools, LLC
Powered by Community Server (Commercial Edition), by Telligent Systems