crm 2011 api avoid deadlocks in plugins

Posted on Posted in CRM 2011 SDK, CRM 2013 SDK, Microsoft, MS CRM 2011, MS CRM 2013, MS Dynamics, MS Dynamics CRM

How to avoid dead locks when using CRM SDK/API 2011

We had an issue with one of our plugin in CRM 2011 where thousands of records were being updated and we were using CRM API QueryExpression to fetch few records.

At the start we didn’t have any issue however later we started getting dead locks.

Did some research and finally figured out the we could use NoLock = true in QueryExpression to avoid this situation.

Now we our queries like below in Plugins and all works perfectly

QueryExpression _contact= new QueryExpression(“contact”);
_contact.NoLock = true;
_contact.ColumnSet = new ColumnSet(true);
_contact.Criteria.AddCondition(“statecode”, ConditionOperator.Equal, 0);
EntityCollection _entityContact = localContext.OrganizationService.RetrieveMultiple(_contact);

Hope this helps.