1

In our install script, which installs several solutions together, we found that solutions were occasionally failing to deploy with the following error in the ULS log:

System.Data.SqlClient.SqlException: Violation of PRIMARY KEY constraint 'PK_Classes'. Cannot insert duplicate key in object 'dbo.Classes'.

This occurs with both Powershell and stsadm.

1 Answer 1

2

We had logic that was calling Install-SPSolution twice on different solutions (same behavior observed with stsadm), and then logic for waiting for the deployment to complete. In rare instances, what happened, is that both solutions were attempting to acquire the deployment lock before either thread got the lock; one thread would succeed and one would fail with the Primary Key exception.

So the log would look like:

Solution Deployment : Acquiring deployment job lock for server ... solutionA.wsp  
Solution Deployment : Acquiring deployment job lock for server ... solutionB.wsp  
Solution Deployment : Successfull ACQUIRED deployment job lock for server ... solutionA.wsp 
System.Data.SqlClient.SqlException: Violation of PRIMARY KEY constraint 'PK_Classes'. Cannot insert duplicate key in object 'dbo.Classes'.

Instead of:

Solution Deployment : Acquiring deployment job lock for server ... solutionA.wsp  
Solution Deployment : Successfull ACQUIRED deployment job lock for server ... solutionA.wsp 
Solution Deployment : Acquiring deployment job lock for server ... solutionB.wsp

(followed by solutionB being denied and waiting for solutionA to finish)

The solution is to install one solution, wait for it to complete, then install another. There's some samples of how to wait using the JobExists property on the solution here: Detecting Solution Deploying Status. It's not really any slower to do it this way (no more than your waiting interval), because behind the scenes SharePoint runs one job and then the other anyways when the locks are properly acquired.

4
  • I thought if I posted the question and answer together it would already be marked as answered. Posting because I thought it might help others who run into the same or similar SQL errors (look for threading issues!)
    – lgaud
    Commented Jul 11, 2013 at 20:02
  • Won't the sptimer job allow you to programatically wait for one job to be finished before starting another?
    – BlueBird
    Commented Jul 11, 2013 at 20:29
  • @lguad Nope, you have to come back after a certain time period and mark it as the answer. Commented Jul 11, 2013 at 22:19
  • @BlueBird I added some information about how to wait to the answer. I posted this because the error you do get in this scenario in that 1% of the time where the locks don't work properly is very obscure :)
    – lgaud
    Commented Jul 12, 2013 at 11:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.