Optimistic vs Pessimistic locking

Pessimistic locking:

The row is locked in advance once one of  its attribute is changed. If anyone else attempts to acquire a lock of the same row during this process, he will be forced to wait until the first transaction has completed. This is achieved by using the familiar SELECT…FOR UPDATE syntax. This is the safest locking mode because two transactions will never make inconsistent change to the same row. However, this locking mode has disadvantages such that:

  1. If a user selects a record for update, and then leaves for lunch without finishing or aborting the transaction. All other users that need to update that record are forced to wait until the user returns and completes the transaction, or until the DBA kills the offending transaction and releases the lock.
  2. The Deadlock – Users A and B are both updating the database at the same time. User A locks a record and then attempt to acquire a lock held by user B – who is waiting to obtain a lock held by user A.

Optimistic locking:

Optimistic Locking is a strategy where you read a record, take note of a version number and check that the version hasn’t changed before you write the record back. When you write the record back you filter the update on the version to make sure it’s atomic. (i.e. hasn’t been updated between when you check the version and write the record to the disk) and update the version in one hit.

If the record is dirty (i.e. different version to yours) you abort the transaction and the user can re-start it.

This strategy is most applicable to high-volume systems and three-tier architectures where you do not necessarily maintain a connection to the database for your session. In this situation the client cannot actually maintain database locks as the connections are taken from a pool and you may not be using the same connection from one access to the next.

Reference: http://stackoverflow.com/questions/129329/optimistic-vs-pessimistic-locking



Leave a comment

Filed under Cloud Computing, Database

Installing CRM 2011 with SQL Server 2012 on Windows Server 2012

How to install CRM 2011 using SQL server 2012 on Windows Server 2012

1. Install Windows Server 2012.

2. Fulfill pre-requisites by installing SQL Server 2012 with SSRS.

(Assume that you already have Active Directory domain and your server has been joined it. If you still don’t have the Active Directory installed, please refer to the following link.)


3. If you have an error of installing Microsoft Visual C++ Runtime failed, uninstall the Microsoft Visual C++ Runtime first then try to install CRM again.

4. If you have an error of Windows Identity Foundation failed, install Windows Identity Foundation feature in your server then try to install CRM again.

5. Make sure you installed the following features in your server.

Server Manager – Manage – Add Roles and Features

· File and Storage Services

· Web Server (IIS)

· .Net Framework 3.5 Features

· .NET Framework 4.5 Features

· Windows Search Service

6. Make sure you have the latest updates installed in your windows server 2012.

7. To install CRM on Windows 2012 you will need to download the CRM setup from the Microsoft Download website. You won’t be able to use your iso image as it does not contain the slipstreamed UR6 package.

8. Get the updates for CRM 2011 to install in Windows Server 2012 using CRM installation wizard. If you don’t have internet connection or you cannot get the updates from the wizard, reference to the following url to get updates from Microsoft from this url “http://support.microsoft.com/kb/2434455“. The download contains all of the languages of the SHS and so you need to select the one that matches the base language of your CRM installation. Extract the cab file for your language and inside you will find a ‘.msp’ package.

9. Create the config.xml file so that the installer will pick up the updates from your update patch file.






10. Extract your installation package.





11. After extraction, run the SetupServer.exe and provide the config file details so that the SHS is used.

212. The checking for update step should show “Setup has finished downloading the update” to confirm that the setup has picked the SHS up correctly from the config file. After this step, the installation process is the same as what you did for Windows Server 2008R2.

Good Luck! 🙂


Reference: http://blogs.msdn.com/b/emeadcrmsupport/archive/2013/05/21/installing-crm-2011-on-windows-server-2012.aspx

Leave a comment

Filed under Uncategorized

Disabling Autoconfiguration IPv4 Address

How to disable Autoconfiguration IPv4 Address

Sometime when you setup your server to virtual machine using LAN or wifi, you chose Bridge mode to share internet connections between host and virtual machine. And when you assign static IPs to your virtual machines, you may encounter ipconflict or duplicate ips errors. When you run ipconfig/all from command prompt, you will see there are two IPv4 address showing. One is autoconfiguration IPv4 address and the other one will be your static IPv4 address. So we need to turn off the autoconfiguration IPv4 feature in order to have our static IP working. Please follow the steps below to turn off it. (The steps are to be done in virtual machines.)

Open the command prompt.

1. netsh interface ipv4 show inter

The network interfaces in your virtual machine will be shown. Note down your Local Area Connection ‘Idx’ number.

2. netsh interface ipv4 set interface YOUR LAN Idx NUMBER dadtransmits=0 store=persistent

3. Open services.msc and disable DHCP Clients service.

4. Restart your virtual machine.

(Reference: http://lyngtinh.blogspot.sg/2011/12/how-to-disable-autoconfiguration-ipv4.html)

Leave a comment

Filed under Networking

Restore Backup Database Failed Because Database Is in Use

How to restore backup database while the existing database is in use

Sometimes, backing up and restoring database is not so straight forward. I used to get the issue of the current database is in use and cannot restore the backup database. But my life is saved when I found the following scripts. 🙂



FROM DISK = N'[file address]'



Leave a comment

Filed under Failed to Restore Backup Database, Microsoft SQL Server

UTC time and Local time in CRM 2011

How to convert UTC time into local time in CRM 2011

Sometimes, we need to Convert UTC time into local time for various reasons. If you are in that condition, here is the some lines of code for you to do it.

private static string RetrieveLocalTimeFromUTCTime(DateTime utcTime, string crmUri)
ClientCredentials credentials = new ClientCredentials();
credentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials;
Uri organizationUri = new Uri(crmUri);

using (OrganizationServiceProxy serviceProxy = new OrganizationServiceProxy(organizationUri, null, credentials, null))
IOrganizationService _serviceProxy = (IOrganizationService)serviceProxy;

var _timeZoneCode = _serviceProxy.RetrieveMultiple(
new QueryExpression(“usersettings”)
ColumnSet = new ColumnSet(“timezonecode”),
Criteria = new FilterExpression
Conditions =
new ConditionExpression(“systemuserid”, ConditionOperator.EqualUserId)

var request = new LocalTimeFromUtcTimeRequest();
request.TimeZoneCode = (int)_timeZoneCode;
request.UtcTime = utcTime.ToUniversalTime();

var response = (LocalTimeFromUtcTimeResponse)_serviceProxy.Execute(request);

return response.LocalTime.ToString();

Leave a comment

Filed under Convert UTC time into Local time, MS Dynamic CRM 2011

CRM 2011 SOP Integration Mode

How to turn on SOP Integration Mode in CRM 2011

If you want to integrate your CRM 2011 Organization with a separate ERP or Finance system using a product like Scribe or SmartConnect, Dynamics CRM 2011 SOP Integration Mode will make it much easier for you to do. It is not known much and hardly documented setting.

The “IsSOPIntegrationEnabled” setting makes the following changes:

  • Replaces the ‘Create Invoice’ button on the Sales Order ribbon with a ‘Submit Order’ button
  • Enables a series of ‘Submitted Status’ fields on the Sales Order entity and Sales Order properties window
  • Enables a ‘Submitted’ statecode value for the Sales Order entity
  • Allows you to specify an ‘Integration User’ that can then make changes to Sales Order and Invoice records through the SDK that would normally be read-only to all other users.

With integration mode enabled, this process flow is possible:

  1. CRM User submits a Sales Order (making the record read-only to normal users)
  2. Integration software picks up the CRM sales order and creates a record in your ERP system
  3. The CRM ‘Integration User’ account can write back to the CRM Sales Order to indicate that it has been successfully created in your ERP system.  This would need to happen through the SDK running in the context of the user account that has been marked as the integration user.
  4. The Finance Department can review the sales order, apply taxes and currency changes etc. to the record, then post it in the ERP system.
  5. The Integration picks up posted Invoices from your ERP system and creates a copy in CRM for reference by CRM users.
  6. As payments are applied to the invoice in your ERP system, another integration updates the payment status of the copy Invoice in CRM.

Turning this mode on takes a few steps, the “IsSOPIntegrationEnabled” value is held in the OrganizationBase table of your CRM Organization database.  Updates direct to SQL are unsupported, but Sonoma Partners have recently released this tool  that allows you to make changes to the OrganizationBase table in a supported way. But if you want to do it by yourself with C#, the following lines of codes will help you to do so.

public static void ActivateIntegrationMode(string CRM_USERNAME, string CRM_PASSWORD, string CRM_DOMAIN, string CRM_ORG_URL, bool turnOn)
ClientCredentials credentials = new ClientCredentials();
credentials.Windows.ClientCredential = new NetworkCredential(CRM_USERNAME, CRM_PASSWORD, CRM_DOMAIN);
Uri organizationUri = new Uri(CRM_ORG_URL);

using (OrganizationServiceProxy serviceProxy = new OrganizationServiceProxy(organizationUri, null, credentials, null))
IOrganizationService _serviceProxy = (IOrganizationService)serviceProxy;

Guid orgId = ((WhoAmIResponse)_serviceProxy.Execute(new WhoAmIRequest())).OrganizationId;
Guid userId = ((WhoAmIResponse)_serviceProxy.Execute(new WhoAmIRequest())).UserId;

//– Update Org to SOP Integration Mode
if (turnOn)
Entity org = new Entity(“organization”);
org[“issopintegrationenabled”] = true;
org[“organizationid”] = orgId;

//– Update User to Integration Mode
Entity user = new Entity(“systemuser”);
user[“systemuserid”] = userId;
user[“isintegrationuser”] = true;
Entity org = new Entity(“organization”);
org[“issopintegrationenabled”] = false;
org[“organizationid”] = orgId;

//– Update User to Integration Mode
Entity user = new Entity(“systemuser”);
user[“systemuserid”] = userId;
user[“isintegrationuser”] = false;

[Reference: http://crmuk.wordpress.com/2012/11/21/crm-2011-sop-integration-mode/]

Leave a comment

Filed under MS Dynamic CRM 2011, SOP Integration Mode

Passing Calling User to an Aspx Page from Sitemap in CRM 2011

How to Pass the Calling User to an Aspx Page from Sitemap in CRM 2011

First, you need to create a simple HTML file and put the following codes in that page. Add the HTML file into the web resource. Call that file from your Sitemap. By the way, don’t forget to redirect to your aspx page in the HTML file. 🙂

<BODY onload=redirectAspxPage(); contentEditable=true>
<SCRIPT type=text/javascript src=”../ClientGlobalContext.js.aspx”></SCRIPT>

<SCRIPT type=text/javascript>
function redirectAspxPage() {

var userid = window.parent.Xrm.Page.context.getUserId();

window.location.href = “http://YOUR_URL/YOUR_PAGE.aspx?userid= ” + userid;


Filed under Passing Calling User to an Aspx Page from Sitemap

Disable Form Fields in CRM 2011

How to Disable Form Fields in CRM 2011

This article is different from the previous one. This time, we are going to disable all the fields on a form in CRM 2011. The sample Java script is shown below.

function disableFormFields(onOff) {
Xrm.Page.ui.controls.forEach(function (control, index) {
if (doesControlHaveAttribute(control)) {

function doesControlHaveAttribute(control) {
var controlType = control.getControlType();
return controlType != “iframe” && controlType != “webresource” && controlType != “subgrid”;

Leave a comment

Filed under Disable Form Fields, MS Dynamic CRM 2011

Readonly Entity Form in CRM 2011

How to Redirect to a Readonly Entity Form in CRM 2011

Sometimes, if you want to have a readonly form in CRM 2011, this article is what you want. We can call the following URL for readonly form in CRM 2011.

http://SERVER Name/ORG NAME/_forms/print/custformprint.aspx?

Query String Parameters

Parameter Value Comment
allsubgridspages Optional
true or false.
Default is false.
If CRM form has a Sub-Grid in it, this parameter decides whether to show Paging for the SubGrids. If set to true, it will show all the records of Sub-Grid, without any Pagination.
id Mandatory GUID. Guid of CRM entity record
formid GUID.
Form Id, if not given it and if there are multiple forms available for given entity it will follow CRM’s way of showing appropriate form.
objectType Mandatory Number. Object Type Code for Entity

Here is the sample Java script for that.

changeToReadOnlyPage = function()Here is the sample JavaScript function.


if( Xrm.Page.ui.getFormType()== CRM_FORM_TYPE_CREATE)
window.location =Xrm.Page.context.getServerUrl() + “/” + Xrm.Page.context.getOrgUniqueName() +
“/_forms/print/custformprint.aspx?objectType=” + Xrm.Page.context.getQueryStringParameters().etc;
else if( Xrm.Page.ui.getFormType() != CRM_FORM_TYPE_READONLY)
window.location = Xrm.Page.context.getServerUrl() + “/” + Xrm.Page.context.getOrgUniqueName() +
“/_forms/print/custformprint.aspx?id=” + Xrm.Page.data.entity.getId()+ “&objectType=” + Xrm.Page.context.getQueryStringParameters

Leave a comment

Filed under MS Dynamic CRM 2011, Readonly Entity Form

Flat File Inbound Sample

Flat file is a very common method to transfer data from one system to another. We will learn the basic in how to use flat file as an inbound data and send to another system. In this example I will read the flat file and transform it into xml file and write into a folder. The sample flat file is shown as below. And I will use “|” as a delimiter between fields and new line as a delimiter between records.




You can start creating the BizTalk Project by following these steps.

1. Create a flat file schema.


2. Set the Root delimiter as new line characters “0x0D 0x0A”. Make sure the delimiter type is Hexadecimal.



3. Set the child delimiter as “|” and make sure the delimiter type is Character.


4. Create a Map and select the source schema and destination schema. In this sample they will be the same.



5. Map the source schema to destination schema.


6. Create an orchestration.


7. Create the receive port and port type. Choose the correct schema for receive port.








8. Create the receive message and send message and assign the correct schema.



9. Transform the received message into send message by using the map.










10. Create the send message object, send port and send port type. Assign the schema to the send port.














11. Set the Activate to True for Receive Message control.



12. Create a custom pipeline.





13. Deploy the project and create the Receive Ports, Receive Locations and Send Ports.







14. Drop the flat file into the folder which is assign to the receive port location and you will get the output file as shown in the figure in your send port location folder.



Leave a comment

Filed under Flat File Inbound, Microsoft BizTalk Server 2010