Create Proc p_GrantInheritedAccess @ReferencingObjectId uniqueidentifier, @ReferencingObjectTypeCode int, @ReferencedObjectId uniqueidentifier, @ReferencedObjectTypeCode int As Begin SET NOCOUNT ON -- For a new entity (Create scenario) ReferencingObjectId is not shared to any principal yet. -- This check reduces by 50% cost of execution for create scenario (no sharing for referencing object exists) if (exists(select ObjectId from PrincipalObjectAccess poa1 with(NOLOCK) where poa1.ObjectId = @ReferencingObjectId AND poa1.ObjectTypeCode = @ReferencingObjectTypeCode)) Begin -- Update Existing rows in POA that indicate that the referencing object was already -- shared to the principals that have share access to the referenced object UPDATE poa1 SET InheritedAccessRightsMask = poa1.InheritedAccessRightsMask | poa2.AccessRightsMask | poa2.InheritedAccessRightsMask | 0x08000000 FROM PrincipalObjectAccess poa1 JOIN PrincipalObjectAccess poa2 ON (poa1.PrincipalId = poa2.PrincipalId) WHERE poa1.ObjectId = @ReferencingObjectId AND poa1.ObjectTypeCode = @ReferencingObjectTypeCode AND poa2.ObjectId = @ReferencedObjectId AND poa2.ObjectTypeCode = @ReferencedObjectTypeCode End -- This check reduces by 50% cost of execution (no sharing for referenced object exists) if (exists(select ObjectId from PrincipalObjectAccess with(NOLOCK) where ObjectId = @ReferencedObjectId AND ObjectTypeCode = @ReferencedObjectTypeCode)) Begin -- insert new rows for principals who were shared the referenced Object but not -- the referencing Object INSERT into PrincipalObjectAccess ( PrincipalId, PrincipalTypeCode, ObjectId, ObjectTypeCode,AccessRightsMask, InheritedAccessRightsMask) SELECT PrincipalId, PrincipalTypeCode, @ReferencingObjectId, @ReferencingObjectTypeCode, 0, AccessRightsMask | InheritedAccessRightsMask | 0x08000000 FROM PrincipalObjectAccess WHERE PrincipalId NOT IN (SELECT PrincipalId FROM PrincipalObjectAccess WHERE ObjectId = @ReferencingObjectId AND ObjectTypeCode = @ReferencingObjectTypeCode) AND ObjectId = @ReferencedObjectId AND ObjectTypeCode = @ReferencedObjectTypeCode End End
I am getting SQL Server real-time blocks in CRM 2011. Please let me know if anyone has any idea when exactly this stored procedure calls in CRM 2011.