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

http://mjabr.wordpress.com/2011/06/10/differences-between-pessimistic-and-optimistic-locking/

Advertisements

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.)

http://social.technet.microsoft.com/wiki/contents/articles/12370.step-by-step-guide-for-setting-up-windows-server-2012-domain-controller.aspx

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.

<CRMSetup>

<Server>

<Patch update=”true”>c:\YOUR_UPDATE_FILE_LOCATION\YOUR_UPDATE_FILE_NAME.msp</Patch>

</Server>

</CRMSetup>

10. Extract your installation package.

 

 

1

 

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. 🙂

USE MASTER
GO

ALTER DATABASE MyDatabase
SET SINGLE_USER WITH ROLLBACK IMMEDIATE
Go

RESTORE DATABASE MyDatabase
FROM DISK = N'[file address]'
Go

ALTER DATABASE MyDatabase
SET MULTI_USER with ROLLBACK IMMEDIATE
Go

 

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)
}
}
}).Entities[0].Attributes[“timezonecode”];

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;
_serviceProxy.Update(org);

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

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

[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. 🙂

<HTML><HEAD><TITLE></TITLE></HEAD>
<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;
}
</SCRIPT>
</BODY></HTML>

2 Comments

Filed under Passing Calling User to an Aspx Page from Sitemap