I've been programming since the '70s and we've been addressing problems like
this for decades. I often suggest another approach: don't design apps that
permit two (or more) clients to work on the same row at the same time. For
example, in many situations you can prevent many collisions by making sure
that client X only has access to a subset of the rows. That is, make sure
that specific clients are assigned a specific geographic region or type of
customers. In some cases clients have access to the same row, but different
columns. This takes even more finesse than ADO.NET is capable of handling in
its present state.
I think it's more important to design intersections to prevent collisions
than worry about where to place the ambulances to pick up the pieces after a
crash.
If you start your design with this point of view, the course of action you
take when there is a collision is far clearer. No, this approach does not
work universally. But take a closer look at the real situations where
collisions occur. Why is the same row being updated by more than one client?
Ok, suppose that there are situations where there are opportunities for
multiple operations on the same row. In these cases, it makes sense to
monitor the server-side data more closely. This is where server-side cursors
come into play and these can be implemented using ANSI cursors with ADO.NET.
It means that you'll have to requery periodically to get the current state
which is not easy with an ASP program, but is simple with a WinForm
application. And if the server-side state changes, you still need to resolve
the conflict. The techniques already discussed are well established and
understood.
Yes, you can use pessimistic locking, but this takes quite a bit discipline
as it can lock more than a single row. You also have to make sure that the
lock is released in a timely fashion to permit other legitimate access.
ADO.NET supports this approach as well with Transactions that implement
Repeatable Read concurrency. However, I've found that my designs are often
far more complex to support client-managed locking or transaction
management.
hth
--
____________________________________
Bill Vaughn
MVP, hRD
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________