How to – Using Server-side concurrency control with Dynamics CRM

25th Dec 2019
  • +0
Share on
close
  • +0
Share on
close
Share on
close

Concurrency control is the mechanism through which outcome of the update \ delete operation of a record is defined, when you have multiple user working on a same record at the same time i.e. concurrently.


We have basically 2 types of concurrency control.


Optimistic concurrency control in which you don’t allow update to the record, if it is updated since it was retrieved.


In Pessimistic concurrency control, the record is itself locked so that other users are not able to access them.


Dynamics CRM currently offers only Optimistic Concurrency control. It is supported on all OOB entities enable for offline sync along with all the custom entities.


You can check for IsOptimisticConcurrencyEnabled property for the entity to check if is Optimistic Concurrency is enabled of the entity or not.


To apply this behaviour, you can use ConcurrencyBehaviour property of UpdateRequest and DeleteRequest. This property can also available for OrganizationServiceContext class, which effectively applies to all the update and delete requests using that context.


To see it in action, CRM programmers will take an example of an existing contact record in Dynamics CRM.


existing contact record


Let us create a sample application to test the concurrency behaviour.


Create a sample console or windows application in Visual Studio.


Add reference to following NuGet package


nuget package

Use the below sample code for retrieving the record and then update the record.


code for retrieving


Run the application and wait at the breakpoint.


Now go and update the contact record retrieved from Microsoft Dynamics CRM web application.


Run the remaining code block after the breakpoint which updates the same contact record retrieved.


You will get the below exception.


rowversion property


The version of the existing record doesn’t match the RowVersion property provided


You will get this error because after retrieving the contact record in code and then updating it in from the CRM’s web application changes the RowVersion of that record.


The same can be tested for the DeleteRequest.


In the background the concurrency is managed using the VersionNumber column of the underlying SQL tables.


Thus, we saw how easily the Optimistic Concurrency can be applied in Microsoft Dynamics CRM, which insures and reduces that there are no data loss when we have chances of multiple users working with the same record.

How has the coronavirus outbreak disrupted your life? And how are you dealing with it? Write to us or send us a video with subject line 'Coronavirus Disruption' to editorial@yourstory.com

    This is a YourStory community post, written by one of our readers.The images and content in this post belong to their respective owners. If you feel that any content posted here is a violation of your copyright, please write to us at mystory@yourstory.com and we will take it down. There has been no commercial exchange by YourStory for the publication of this article.
    • +0
    Share on
    close
    • +0
    Share on
    close
    Share on
    close