Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Optimistic Concurrency in VB .NET

Status
Not open for further replies.

sqlsamurai

Programmer
May 11, 2005
120
US
I have begun to investigate concurrency in VB .NET. I studied these two links below... and while they have good information there were a couple things they didnt address.

Walkthrough: Handling a Concurrency Exception

Visual Studio .NET Developer: Coding for Concurrency in ADO.NET

1. Lets say you have made more than one change in more than one record. A concurrency exception will only be raised on the first one it finds. If you decide to apply the change in question then all other updates will be applied also. If you decide not to apply the change in question then all other changes will be discarded also. I'm not sure how to deal with each concurrency exception separately, or if there is a way.

2. Plus like I mentioned in number 1, there is no way to iterate through all the concurrency errors. the concurrency exception itself holds only one, the first one.

I was wondering how you guys handle concurrency in vb .net? I also think it would be neat if somebody wrote a robust data layer that handles concurrency, that they were willing to sell. Similar to the DAAB (Data Access Application Block). But i dont think the DAAB works in a data-binding environment.
 
I haven't had to worry about this much on my current projects. Most of the data writing apps are automated and limited, so there is little to no possibility of concurency issues causing a problem. But there have been a few good discussions here on using time stamps to check for changes before commiting, using transactions, and the like. I don't know of any ready to go solutions, although at this level of complexity you are likely looking at a base class that controls all functionality and inheriting it into child classes to expose data for specific entities.

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
I recently just finished a concurrency procedure for a multi-user application.

My app uses stored procedures for all commands of the data adapter. For the update stored procedure, I have a logic check that uses a passed in timestamp and checks to see if it is different. If so, the stored procedure returns a 0 and does not perform an update (no errors are thrown in code)

My code checks to see if a 0 is returned and if so, advises the user that someone made a change already and gives them two options, one to overwrite with there changes, or two to discard their changes and refresh the dataset. If they select to overwrite, than I have another Update Stored Procedure that doesn't use the timestamp (just PK's) and I call that, pass the values on the form, and update the database with the users values
If they choose to discard, then I ds.clear() and refill the datset with the dataadapter and find the record they were on.
 
Note, this type of solution is for one concurrency problem at a time and wouldn't handle your problem #1. I would never have the need to check for multiple concurrency problems because I call my updates on a record to record basis (my user form uses data binding).

As to functions that may be called to do mass updates outside of a user interface, I haven't gotten there yet but I gather that I will use some sort of similar setup with returning a 0 in a loop and dealing with it the moment it comes up or tracking it in an array and working on the records that have problems in a different loop.
 
The only thing which comes to mind is to save off a DataSet with .GetChanges(). Then you could iterate through all of the rows in the Changes and create a new dataset for each row--and try to update each new dataset individually.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top