Locking mechanism in MS CRM

When CRM is interacting with SQL server what exactly happening in terms of locking at database?..., Here I am trying to articulate the locking mechanism at my best.

When CRM trying to interface with SQL server, SQL server determines which locks it should be apply against a record or table.




  1. If CRM is trying to read a record, SQL server applies Read lock on that record.
  2. If CRM is trying to read multiple of records, SQL server decides whether it should apply Read lock on entire table or respective records
  3. If CRM is creating a record, SQL server applies Write lock on that record.
  4. If CRM is updating a record, CRM will applies write lock on that record.
  5. There may be scenarios SQL server does not apply any locks.
CRM executes all the request under a single transaction each time it is hitting database, SQL server holds the lock until transaction completed. Once the transaction is completed SQL server will release the lock on that record or transaction.

Below scenario explains how the system reacts when multiple of users updating the same record at same time.

























When first transaction gets lock and started it execution, second transaction will be blocked until it gets lock on that record i.e. blocked until first transaction complete.


Sometimes blocking may cause timeout issue when the multiple request executes parallel. The first request can easily lock the record and complete it requests, but the second request should wait until the first request release its lock. Similarly, thirst request should also wait until first and second requests to complete. The more requests there are, the longer blocking will occur. If there are enough requests, and each request takes long enough, this can push the later requests to the point that they time out, even though individually they may complete correctly.




You may like below posts

Improving MS CRM Performance

Performance Center in MS CRM 2013

date and time field behavior in MS CRM

Upsert in MSCRM

Ticker Symbol Field in MS CRM

Themes in MS CRM

Enable Tracing in MS CRM

Calculated Field in Dynamics CRM 2015


IME Mode in MS CRM

using Alias in MS CRM

When we are retrieving linked entity related information using FetchXML or Query expression we are using alias attribute to identify the linked entity attributes. Alias name is prefixed to all linked entity attributes.

Below code snippet will give more information on how to use alias in FetchXML.





string fetchXML = @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
                                  <entity name='contact'>
                                    <attribute name='fullname' />
                                    <attribute name='telephone1' />
                                    <attribute name='contactid' />
                                    <attribute name='middlename' />
                                    <attribute name='lastname' />
                                    <attribute name='firstname' />
                                    <order attribute='fullname' descending='false' />
                                    <link-entity name='account' from='accountid' to='parentcustomerid' visible='false' link-type='outer' alias='AliasAccountName'>
                                      <attribute name='donotphone' />
                                      <attribute name='accountclassificationcode' />
                                      <attribute name='createdon' />
                                      <attribute name='crisp_balance' />
                                    </link-entity>
                                  </entity>
                                </fetch>
                                ";
 FetchExpression fetchExpression = new FetchExpression(fetchXML);
 EntityCollection fetchCollection = service.RetrieveMultiple(fetchExpression);

Here “service” is an organization service. Click here for more information on how to create organization service

After you run above fetchxml, the way we are reading account related attributes are bit different than customer related attributes.

Reading alias values for different datatypes:

OptionSet Value:

int aliasOptionsetValue = ((OptionSetValue)((AliasedValue)fetchCollection.Entities[0].Attributes["AliasAccountName .new_status"]).Value).Value;

Lookup:

Guid aliasstateGuid = ((EntityReference)fetchCollection.Entities[0].Attributes["AliasAccountName.crisp_state"]).Id;

string aliasstateName = ((EntityReference)fetchCollection.Entities[0].Attributes["AliasAccountName.crisp_state"]).Name

Money:

decimal aliasamt = ((Money)fetchCollection.Entities[0].Attributes["AliasAccountName.new_balance"]).Value;

Boolean:

bool aliasisactive = Convert.ToBoolean(fetchCollection.Entities[0].Attributes["AliasAccountName.new_isactive"]);

String:

string aliasString = ((AliasedValue)fetchCollection.Entities[0].Attributes["AliasAccountName.new_name"]).Value.ToString();





You may like below posts

Improving MS CRM Performance

Performance Center in MS CRM 2013

date and time field behavior in MS CRM

Upsert in MSCRM

Locking mechanism in MS CRM

Ticker Symbol Field in MS CRM

Themes in MS CRM

Enable Tracing in MS CRM

Calculated Field in Dynamics CRM 2015


IME Mode in MS CRM

Retrieve all entities and attributes metadata in MS CRM

             
Below code snippet will retrieve all entities metadata which includes it's attributes metadata as well.


              RetrieveAllEntitiesRequest metaDataRequest = new RetrieveAllEntitiesRequest();
                RetrieveAllEntitiesResponse metaDataResponse = new RetrieveAllEntitiesResponse();
                metaDataRequest.EntityFilters = EntityFilters.All;

                // Execute the request.

                metaDataResponse = (RetrieveAllEntitiesResponse)service.Execute(metaDataRequest);

              List<EntityMetadata>   entities = metaDataResponse.EntityMetadata.ToList();




Note: "service" is nothing but an organization service you are going to create and you need to include below namespaces...

using Microsoft.Xrm.Sdk.Messages;
using Microsoft.Xrm.Sdk.Metadata;



You may like below posts

Improving MS CRM Performance

Performance Center in MS CRM 2013

date and time field behavior in MS CRM

Upsert in MSCRM

Locking mechanism in MS CRM

Ticker Symbol Field in MS CRM

Themes in MS CRM

Enable Tracing in MS CRM

Calculated Field in Dynamics CRM 2015

IME Mode in MS CRM

Can we register image to custom action in MS CRM?

Answer is No. we can not register images to actions. We can only register images to pre-defined messages like Create, Update, Delete etc.



If you are looking for any attribute values through images, the only options are passing that attribute value as Input parameter or you can write down a fetch xml or Query expression to retrieve those values.




You may like below posts

Improving MS CRM Performance

Performance Center in MS CRM 2013

date and time field behavior in MS CRM

Upsert in MSCRM

Locking mechanism in MS CRM

Ticker Symbol Field in MS CRM

Themes in MS CRM

Enable Tracing in MS CRM

Calculated Field in Dynamics CRM 2015

IME Mode in MS CRM

Featured Post

Improving MS CRM Performance

Performance on MS CRM is always a crucial thing and we may follow different ways to achieve the performance thing. Below is the one more a...