With little bit luck we have narrow down the issue using almost identical steps as you suggested.
Issue happening randomly when users creating a new Contract, happening when different users when they are creating new contract.
I did check the logs on both (web and sql) , when the users experienced this error i have captured this SQL trace + windows event (see below) including upto exact second.
When contract created this it is updating OrganizationBase table by incrementing +1 (which is standard procedure and out of the box to do) to update only 1 row (thats in that table) SQL server taking with 64bit processor 8GB RAM is taking more 30 seconds.
My guess here is when it is updating it is locking the row and causing this error (pure speculation) here is my logs
Here is log from Web server,
Warning dd/mm/yyyy 12:39
MSCRMPlatform
17972
None
Query execution time of 30.0 seconds exceeded the threshold of 10 seconds. Thread: 23; Database: Org_MSCRM; Server:BigServerXXXX;
Query: sp_getapplock.
Warning
dd/mm/yyyy 12:39
MSCRMPlatform
17972
None
Query execution time of 30.0 seconds exceeded the threshold of 10 seconds. Thread: 23; Database: Org_MSCRM; Server:BigServerXXXX;
Query: sp_getapplock.
SQL server here trace log on exact
<Event id="10" name="RPC:Completed">
<Column id="11" name="LoginName">SmallOrg\XXXAdminXRM</Column>
<Column id="15" name="EndTime"></Column>
<Column id="12" name="SPID">105</Column>
<Column id="16" name="Reads">2</Column>
<Column id="1" name="TextData">exec sp_executesql N'declare @currentval int
update OrganizationBase set @currentval = CurrentContractNumber, CurrentContractNumber = CurrentContractNumber + 1 where OrganizationId = @orgid
select @currentval',N'@orgid uniqueidentifier',@orgid='xxxxxxxx-xxxx-xxx-xxxx-xxxxxxxxxxxx'</Column>
<Column id="9" name="ClientProcessID">14976</Column>
<Column id="13" name="Duration">261</Column>
<Column id="17" name="Writes">0</Column>
<Column id="2" name="BinaryData">00000000040000001A00730070005F006500780065006300750074006500730071006C009E01000082001A00E7206E00760061007200630068006100720028003100380037002900760100006400650063006C0061007200650020004000630075007200720065006E007400760061006C00200069006E0074000A0075007000640061007400650020004F007200670061006E0069007A006100740069006F006E004200610073006500200073006500740020004000630075007200720065006E007400760061006C0020003D002000430075007200720065006E00740043006F006E00740072006100630074004E0075006D006200650072002C002000430075007200720065006E00740043006F006E00740072006100630074004E0075006D0062006500720020003D002000430075007200720065006E00740043006F006E00740072006100630074004E0075006D0062006500720020002B002000310020007700680065007200650020004F007200670061006E0069007A006100740069006F006E004900640020003D00200040006F0072006700690064000A00730065006C0065006300740020004000630075007200720065006E007400760061006C005400000082001800E7206E00760061007200630068006100720028003200330029002E00000040006F007200670069006400200075006E0069007100750065006900640065006E007400690066006900650072004800000048002000241075006E0069007100750065006900640065006E007400690066006900650072000C0040006F007200670069006400248A4AD661908F4A81D28BD2ECF449191400000003000600380469006E00740000000000</Column>
<Column id="6" name="NTUserName">XXXAdminXRM</Column>
<Column id="10" name="ApplicationName">.Net SqlClient Data Provider</Column>
<Column id="14" name="StartTime"></Column>
<Column id="18" name="CPU">0</Column>
</Event>
Thanks
Pavan