Handling Concurrency Errors

At times multiple users of your application may edit the same information in a record and try to save changes. This creates a concurrency problem. There are three main scenarios are:

  • Two users grab the same record. The first user updates the record and the second user tries to update the record
  • Two users grab the same record. The first user updates the record and the second user tries to delete the record
  • Two users grab the same record. The first user deletes the record and the second user tries to update the record


Note: To handle concurrency exceptions properly, you need to mark one or more of your entity properties' ConcurrencyMode to Fixed. You can create a TimeStamp column for each table in your database that can be used to determine if a record has been updated or deleted by another user. For details, check out this MSDN help topic: http://msdn.microsoft.com/en-us/library/bb738618.aspx

When the Entity Framework encounters a concurrency conflict, it throws an OptimisticConcurrencyException. The mmBusinessObjectGeneric class catches this exception in its HandleException method and calls its protected HandleConcurrencyException() method which in turn calls the BuildConcurrencyExceptionMessage method. This method builds a message that lists the current data in the database, and the proposed data which can then be displayed to the user. For example:

This message is automatically displayed for you in MM .NET desktop applications.

If you want to handle this code yourself, you can follow this code pattern:

// Save the entity
mmSaveDataResult result = employee.SaveEntity(employeeEntity);
 
// Check if there is a concurrency exception
if (result == mmSaveDataResult.Exception &&
	employee.Exception is OptimisticConcurrencyException)
{
	// Pass true to retain the current users changes,
	// pass false to retain the values in the database
	employee.ResolveConcurrency(true);
 
	// Save the entity again
	employee.SaveEntity(employeeEntity);
}

Changing Default Concurrency Handling Behavior

There are a number of ways you can change the default MM .NET concurrency handling behavior:

  • Override the business object's HandleConcurrencyException method and perform completely different handling logic

  • Override the business object's BuildConcurrencyExceptionMessage method to change how the exception message is built

  • Override the business object's ResolveCurrency method to change how the currency exception is resolved

© (c) 2026 Oak Leaf Enterprises, Inc., 1996-2026 • Updated: 07/29/18
Comment or report problem with topic