StrataFrame Forum

Concurrency Using RowVersion Problem

http://forum.strataframe.net/Topic15079.aspx

By Jeff Pagley - 3/21/2008

Hi Guys,

As I have said before, I am a part time programmer and seem to be little rusty all of the time.  With that said, after following the help instructions, I am unable to get SF concurrency using RowVersioning to work.  User A and User B are editing the same record at the same time using the code below.  User A saves the record.  Then User B saves the record and the BO does not throw an exception.  What am I doing wrong?  Thanks for the help!

I have the following properties set on the ContactsBO:

CollisionNoficationType = ThrowException

RowVersionOrTimestampColumn = ContactRowVersion (datatype int - allow nulls)

UpdateConcurrencyType = OptimisticRowVersion

Code Below..............................

Using loBO As New ContactsBO

loBO.FillByPrimaryKey(contactID)

If loBO.IsEmpty Then

  Return False

Else

  loBO.Edit()

  loBO.UserID = GlobalVariables.CurrentUserID

  loBO.Save()

Return True

End If

End Using

Catch ex As MicroFour.StrataFrame.Data.DataLayerException

MsgBox("DataLayerException ex = " & ex.Message)

Return False

Catch ex As MicroFour.StrataFrame.Data.DataLayerSavingException

MsgBox("DataLayerSavingExeption ex = " & ex.Message)

Return False

Catch ex As MicroFour.StrataFrame.Data.RowNotUpdatedException

MsgBox("RowNotUpdateExeption ex = " & ex.Message)

Return False

Catch ex As Exception

Ems.HandleException(Me, ex)

Return False

End Try

By Trent L. Taylor - 3/21/2008

Well the good news is that I know that there isn't an issue with the RowVersion concurrency...this is probably the most common concurrency logic used Smile.  So we will want to look at your code a little closer.

First, I am not sure what you are trying to accomplish by catching all of the individual exception types...I assume that you have some need for this in your application...so we can just skip over that for now.  Second, you will not want to allow NULLs on the row version field...bad mojo could come BigGrin  Next, you will need to indicate whether you are using CRUD settings, etc. If you are using the DDT and allowing the sprocs to be created for you, did you set the row version column on the table properties?

You will also notice in that screen shot that the UPDATE procedure will need to have the concurrency set to Optimistic Row Version as well.

Also, you should just set the BO CRUD properties on through the BO designer versus in code each time...it you are going to have the same concurrency type each time, which you should.

Finally, you will want to handle the COncurrencyException event versus trying to catch the exception as you currently are.  If there is a concurrency collision, the ConcurrencyException event will be raised...that is where you will want to place your logic...not a bunch of Try/Catches.

Hopefully one of these suggestions should get you going. Smile

By Jeff Pagley - 3/22/2008

Hi Trent,

I am not using CRUD or DDT.  As I show you in the code, I am just using the BO.Fill, BO.Edit and BO.Save methods to update a field.  Therefore, how do I handle or trap for the concurrency issue using SF when User A and User B are editing and updating the field at the same time?

Thanks.

By StrataFrame Team - 3/24/2008

By default, you can capture the ConcurrencyException event on the business object.  When the second user goes to save and the concurrency exception is detected, that event will be raised.  However, if you change the CollisionNotificationType property on the business object to ThrowException, then a DataLayerSavingException will be thrown that contains the information about the concurrency exception that was encountered. 

So, it's really up to you as to how you want to handle the error.  If you capture the event, you can set the Resave property on the event args to True and the data layer will re-save the record after the event handler returns and you're original call to Save() will never know there was an error.  If you catch the exception, then you'll need to call Save() again after you're done what you want to with the data.

By Jeff Pagley - 12/16/2009

In the ConcurrencyExeption event, I have set the e.ResaveRecord = True, but the SF Softcollision form is still appearing.  I thought if I set the e.ResaveRecord if would force the local record to be saved and the SF softcollision form will NOT appear.  Is there way to handle this so that the SF softcollision form does not appear to the user?  Please explain the best practices in this case.

I am using OptimisticRowVersion.

Thanks,

Jeff

By Ivan George Borges - 12/16/2009

Hi Jeff.

Have a look at this post: http://forum.strataframe.net/FindPost6191.aspx

Follow it and I think you will find some good information about concurrency.

Hope it helps.