none
Optimistic Concurrency Violation Display Options RRS feed

  • Question

  • I am writing an application in vb.net using optomistic concurrency and have initially handled concurrency violations using something similar to the code in this walkthrough: http://msdn.microsoft.com/en-us/library/ms171936(v=VS.90).aspx

    This is a good start and shows the original, proposed and current values to the user. However, the presentation is not very user friendly. Many of my tables have columns that only stored a surrogate ID in the database (an integer which is foriegn key to another table). for instance, the order table has a customerID column which stores an integer. But this integer refers to a customer name in the customer table. Using the code from the walkthrough, the user is only presented with the integer, not the actual customer name. This integer has little meaning to the user. Additionally, the column names are not presented, so the user does not know what all the integers mean.

    I'm looking for a way to present this information using the actual customer name and perhaps only showing the columns where the data has changed since it was retrieved from the database (The user doesn't need to see every column on the error dialog). Perhaps displaying this in a datagridview with the columns being Original, Current and Proposed and the rows being the columns from the database with discrepencies.

    • Edited by Technobeam Tuesday, December 21, 2010 5:32 AM
    Saturday, November 27, 2010 7:01 PM

All replies

  • Hello,

    I think you can create a typed dataset and add a datatable with the columns you really want. You can create and add it with any datatable in database even there are foreign key constraints on the customer table and another table (it is CustomerContact in the walkthrough you mentioned).  However, there is also a restriction: you can not add insert/update/delete command to this dataset.

    For the concurrency issue, you can wrapp your code in a try-catch block and handle the exception in the catch block. Here is an example showing how to show the exception message in a Label control when concurrency exception occurs, I hope it could help you:
    http://msdn.microsoft.com/en-us/magazine/cc163924.aspx


    Best Regards,
    Roahn Luo
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg@microsoft.com
    Tuesday, November 30, 2010 10:00 AM
  • That article is somewhat helpful. However, I was hoping for a more step-by-step answer. I can handle the concurrency effectively from a variation of the code in the original article I posted. However, the presentation isn't the best and doesn't give the user the information they really need. I was hoping to hear some suggestions of how other people have handled concurrency in .Net windows forms applications.
    Wednesday, December 1, 2010 2:40 PM
  • Hello,

    It denpens on the specific business of your application on how to handle the errors. But to improve the users experience, the usual strategy is to enable the users to decide how to handle the concurrency errors by providing an error handler to the users and display various options, if users have a response, process it and then decide we should resend the update, or reset the data in dataset.

    The information you could display contains the current record in database, the original value and the proposed changes in dataset. Users can decide whether overwirte the database with the proposed version or cancel the update.

    Here is a step-by-step walkthrough showing the strategy, I hope it could help you:
    http://msdn.microsoft.com/en-us/library/ms171936(VS.80).aspx


    Best Regards,
    Roahn Luo
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg@microsoft.com
    • Marked as answer by liurong luo Monday, December 6, 2010 2:26 AM
    • Unmarked as answer by Technobeam Tuesday, December 21, 2010 4:33 AM
    Thursday, December 2, 2010 2:21 AM
  • Roahn,

    I had already been modeling my concurrency exception handling after the link you had suggested. I just need to come up with a more user friendly way of presenting the Original, Proposed and Current records. the walkthrough presents them as a comma seperated string. This can get a bit combersome especially when dealing with tables containing a large number of columns. Can you help me through the code in VB to get the three options into a datatable and display them in a datadgridview? This would allow me to write code to hide the columns that are matching in Original, Proposed and Current and only show the columns with differences. I can also convert the IDs (unmeaningful integers) to their display name from their parent table using datagridviewcomboboxes.

    I've tried a bunch of things, but I really don't know how to construct the code to pull these three versions into a temporary datatable to display them.

    Also, the code in the walkthrough handles one table at a time. I'm hoping to build my code to be universal with paramters allowing me to handle concurrency in the same way with all the tables in my dataset.

    Tuesday, December 21, 2010 4:42 AM