John
3/26/2008 8:44:00 PM
Hi Kerry
Many thanks for this insight. Is there an easy way to display both new and
old row values to the user to let him/her select?
Thanks
Regards
"Kerry Moorman" <KerryMoorman@discussions.microsoft.com> wrote in message
news:287D48C5-72D5-4A42-A59F-211AF9599F66@microsoft.com...
> John,
>
> You need to decide how you want to handle concurrency issues in a
> particular
> application.
>
> For example, how do you want to handle this situation:
>
> Mary loads your employee record from the Employees table into the Employee
> Manager application. She loaded your record because your cell phone number
> has changed and she is updating that piece of information in your record.
>
> While Mary is working on your record, Jim loads your employee record from
> the Employees table into the Employee Manager application. He loaded your
> record because you have just gotten a big raise and he is updating that
> piece
> of information in your record. He changes your salary and updates your
> record
> in the database.
>
> Mary has now finished changing your cell phone number and attempts to
> update
> your record in the database.
>
> Do you want Mary's update to succeed? If it does you have just lost your
> raise because her update will overwrite your new salary that Jim entered
> with
> your old salary as it was when Mary loaded your record.
>
> Do you want Mary's update to fail because of a concurrency conflict? When
> it
> fails, how do you want to deal with the conflict?
>
> Your current code appears to read the updated record and then apply the
> old
> values to it. This gets rid of the concurrency conflict but you still end
> up
> with your old salary instead of your raise.
>
> My choice would be to inform the user that the record has been changed by
> another user and let the user reload the record and start over.
>
> Kerry Moorman
>
> "John" wrote:
>
>> So Kerry how do I handle it? which was my original question.
>>
>> Regards
>>
>>
>> "Kerry Moorman" <KerryMoorman@discussions.microsoft.com> wrote in message
>> news:31F1C265-0B1C-40DB-8174-3A5F6DA4DD8F@microsoft.com...
>> > John,
>> >
>> > It looks like your approach to concurrency handling is to get around
>> > the
>> > concurrency error by reloading the data from the database and then
>> > applying
>> > your changes.
>> >
>> > You might as well just turn off concurrency checking, since that is the
>> > end
>> > result anyway.
>> >
>> > In other words, it looks like your code is just avoiding concurrency
>> > exceptions, not handling concurrency conflicts.
>> >
>> > Kerry Moorman
>> >
>> > "John" wrote:
>> >
>> >> Hi
>> >>
>> >> I have developed the following logic to handle db concurrency
>> >> violations.
>> >> I
>> >> just wonder if someone can tell me if it is correct or if I need a
>> >> different approach.Would love to know how pros handle it.
>> >>
>> >> Thanks
>> >>
>> >> Regards
>> >>
>> >>
>> >> Dim dc As DataColumn
>> >> Dim drCache As DataRow
>> >> Dim drCurrent As DataRow
>> >>
>> >> Try
>> >> ' Attempt the update
>> >> daContacts.Update(ds.Contacts)
>> >>
>> >> Catch Ex As DBConcurrencyException
>> >>
>> >> ' First - cache the row
>> >> drCache = ds.Contacts.NewRow()
>> >> For Each dc In ds.Contacts.Columns
>> >> If Not dc.ReadOnly Then
>> >> drCache(dc.ColumnName) = Ex.Row(dc.ColumnName)
>> >> End If
>> >> Next
>> >>
>> >> ' Refresh from database
>> >> daContacts.Fill(ds.Contacts)
>> >>
>> >> ' Position to the faulted row
>> >> drCurrent = ds.Contacts.Rows.Find(Ex.Row("ID"))
>> >>
>> >> ' Apply User Changes
>> >> For Each dc In ds.Contacts.Columns
>> >> If Not dc.ReadOnly Then
>> >> drCurrent(dc.ColumnName) = drCache(dc.ColumnName)
>> >> End If
>> >> Next
>> >>
>> >> ' Save again
>> >> daContacts.Update(ds.Contacts)
>> >> End Try
>> >>
>> >>
>> >>
>>
>>
>>