If you use the BDC to import user profile data, or if you use multiple threads to update the profile database using the profile APIs, you may have encountered SQL deadlocks if you’re trying to update the manager property of the profile.
The issue can be traced down to a couple of stored procedures:
profile_UpdateUserProfileData – Initiates a transaction and updates the user profile table numerous times based on a number of properties passed to it. If manager is updated, this code block runs:
IF @PropertyID = @PROPERTY_MANAGER_ID BEGIN UPDATE UserProfile SET Manager = CAST(@PropertyValue AS NVARCHAR(400)) WHERE RecordID = @RecordID exec dbo.QuickLinksUpdateOrgContacts @RecordID, 1 END
Which calls the QuickLinksUpdateOrgContacts procedure which also attempts to read and update the UserProfile table. This procedure is causing the issues due to reading from the UserProfile table then updating the table within the scope of the transaction started by the profile_UpdateUserProfileData procedure. What is occurring is a lock escalation from the shared lock created during the read to an exclusive lock for the update because the select and update SQL statements are occurring within a transaction. If this occurs across multiple SQL processes, a deadlock can occur.
A couple of observations:
So, how do you avoid this? Well you have a few options:
Hope this helps!