This website is intended as archive for old content and forums.
Please visit http://opf3.codeplex.com for the project's new website.

Technical Support

FORUM TOPIC

Who, what tha..., why? How to set up Opf3 and keep it running smoothly. Search this Forum to find others who have driven down your road and have advice and tips to help you out (btw. we are helping too Happy).

RSS
Larry Marshall
Posted on the 02/16/07 1:03 AM
ConcurrencyException
Reply Quote
 The following code snippets got a ConcurrencyException at the PersistChanges method. What could I be doing wrong?

Private _collFirstName As ObjectSet(Of OPF3.FirstName)
.....
Dim context As ObjectContext = Session.Current.ObjectContext
context.ConcurrencyManager = New Md5ConcurrencyManager
Dim searcher As ObjectSearcher(Of OPF3.FirstName) = context.GetObjectSearcher(Of OPF3.FirstName)()
_collFirstName = searcher.FindAll("ClientID = {0}", Tools.ClientID.ToString)
bsFirstName.DataSource = _collFirstName
ugrdFirstName.DataSource = bsFirstName

.....
Dim clnt As OPF3.FirstName = DirectCast(bsFirstName.Current, OPF3.FirstName)
Dim context As ObjectContext = Session.Current.ObjectContext
Try
Using t As Storages.Transaction = context.StartTransaction()
context.PersistChanges(_collFirstName)
t.Commit()
End Using
.....
Chili.Opf3.Concurrency.ConcurrencyException was unhandled
Message="A concurrency exception happened: Checksums different."
Source="Chili.Opf3"
StackTrace:
at Chili.Opf3.Concurrency.Md5.Md5ConcurrencyManager.OnBeforeUpdate[T](T obj, ConcurrencyManagerEventArgs e)
at Chili.Opf3.ObjectPersister.Update[T](T obj, ObjectInfo objectInfo, PersistDepths persistDepth)
at Chili.Opf3.ObjectPersister.PersistChanges[T](T obj, PersistDepths persistDepth)
at Chili.Opf3.ObjectContext.PersistChanges[T](T obj, PersistDepths persistDepth)
at Chili.Opf3.ObjectSet`1.Persist(ObjectContext context, PersistDepths persistDepth, PersistingTrace persistingTrace)
at Chili.Opf3.ObjectSet`1.Chili.Opf3.ICustomPersister.Persist(ObjectContext context, PersistDepths persistDepth, PersistingTrace persistingTrace)
at Chili.Opf3.ObjectContext.PersistChanges[T](T obj, PersistDepths persistDepth)
at Chili.Opf3.ObjectContext.PersistChanges[T](T obj)
at MailHouse2.Forms.ctrlCullNames.FirstNameBindingNavigatorSaveItem_Click(Object sender, EventArgs e) in \\mombasa\Data\My Documents\Larry\Visual Studio 2005\Projects\MailHouse2\MailHouse2.Forms\ctrlCullNames.vb:line 187


Christian Liensberger [Moderator]
Posted on the 02/16/07 9:22 AM
RE: ConcurrencyException
Reply Quote
 The concurrency manager's goal is: It checks whether another has changed the object in the database, while you had it in memory. This is done, because otherwise your changes are going to overwrite the changes of the thirth person, withouth having you known that somebody else did changes. Means you could overwrite the changes of somebody else without having seen that the other person has changed.

Now the Md5ConcurrencyManager does it by creating checksums. Each time an object is loaded an MD5 is constructed on it. When you update the object (PersistChanges) the concurrency manager does a re-load of the current object (as separate instance) and calculates the checksum (MD5) for that. Now the checksum of your object (the one that is going to be persisted), that has been created during load, is compared to the checksum of the reloaded object. If these don't match the concurrency manager takes this as: somebody changed the object in the storage in the meantime.

Form your code (the one that you pasted) everything seems ok, but perhaps you did another load of the same object in the meantime and had it persisted in the mean time by another thread or another instance of the application?

Regards,
Christian Liensberger

Larry Marshall
Posted on the 02/16/07 2:42 PM
RE: ConcurrencyException
Reply Quote
 Christian,

The object load is done in the form load event. It is a very simple program.

I am using a BindingSource, a BindingNavigator and an Infragistics win grid. After initial load, there are 7020 objects in the collection. When I stopped the program at the BindingNavigator AddNewItem event, there were still 7020 objects in the collection and an open row in the grid for me to add a new object.

When I entered the BindingNavigator SaveItem event, there were 7021 objects in the collection. This event is where I tried to persist the changes and got the error message.

Any suggestions for me to try?

Thanks, Larry



Christian Liensberger [Moderator]
Posted on the 02/16/07 4:21 PM
RE: ConcurrencyException
Reply Quote
 This is strange... How did that object came to the list?

Larry Marshall
Posted on the 02/16/07 4:59 PM
RE: ConcurrencyException
Reply Quote
 Christian,

When you drag an object from the DataSources window to the designer surface containing a form, it automatically creates a BindingSource and a BindingNavigator (a bunch of ToolStrip objects). The BindingNavigator's BindingSource property is automatically set to the BindingSource. Additionally, it creates a DataViewGrid, which I deleted and replaced with an Infragistic's grid.

One of the buttons on the BindingNavigator is the +, the Add New button. Clicking on this button at runtime automatically calls the AddNew method on the associated BindingSource object.

Christian Liensberger [Moderator]
Posted on the 02/16/07 5:06 PM
RE: ConcurrencyException
Reply Quote
 OK!

Are you sure that nobody else changed the object in the database in the meantime? This error is only seen if somebody changed the object while being in memory.

Christian

Larry Marshall
Posted on the 02/16/07 5:26 PM
RE: ConcurrencyException
Reply Quote
 Yes, I am sure. If something is changing, it's beyond me.

Christian Liensberger [Moderator]
Posted on the 02/16/07 5:36 PM
RE: ConcurrencyException
Reply Quote
 

Larry Marshall wrote:
Yes, I am sure. If something is changing, it's beyond me.


Are you formatting the inserted data in the database? Removing digits or so?

Larry Marshall
Posted on the 02/16/07 6:05 PM
RE: ConcurrencyException
Reply Quote
 No

Christian Liensberger [Moderator]
Posted on the 02/16/07 6:32 PM
RE: ConcurrencyException
Reply Quote
 Please send me an e-mail to our support handle. I'll send you our internal release... We have enhanced the MD5 checksum code...

Regards,
Christian Liensberger

Larry Marshall
Posted on the 02/16/07 6:56 PM
RE: ConcurrencyException
Reply Quote
 Christian,

I put together a sample for you. In doing so, I changed all controls to MS removing all Infragistics. The error disappeared. So it is somehow related to the UltraGrid.

Christian Liensberger [Moderator]
Posted on the 02/16/07 7:03 PM
RE: ConcurrencyException
Reply Quote
 

Larry Marshall wrote:
Christian,

I put together a sample for you. In doing so, I changed all controls to MS removing all Infragistics. The error disappeared. So it is somehow related to the UltraGrid.


Are you having circular references in your persistents? Persistent1 -> Persistent2 -> Persistent2?

Christian

Larry Marshall
Posted on the 02/16/07 9:13 PM
RE: ConcurrencyException
Reply Quote
 No, I don't think so.

All times are in GMT.