WSS Content Deployment Violation of Primary Key Constraint Error

Recently at a client’s site, we began experiencing consistent failures of an incremental content deployment job with the following error:

Violation of PRIMARY KEY constraint ‘PK__#ExportObjects____462064A9’. Cannot insert duplicate key in object ‘dbo.#ExportObjects’. The statement has been terminated. at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe) at System.Data.SqlClient.SqlCommand.ExecuteNonQuery() at Microsoft.SharePoint.Utilities.SqlSession.ExecuteNonQuery(SqlCommand command) at Microsoft.SharePoint.Deployment.SPExport.CalculateObjectDependencies(Boolean linksOnly) at Microsoft.SharePoint.Deployment.SPExport.CalculateObjectsToExport() at Microsoft.SharePoint.Deployment.SPExport.Run()

According to this blog entry, this is caused when a single page is approved more than once between incremental updates. Microsoft has a hotfix for this issue that is available via a support call (see Microsoft KB Article 936867).

 I believe that a work around (without the hotfix mentioned above) is to perform a full content deployment job (instead of the incremental). I will be attempting this work around later this evening and will let you know of the results.

 Update

The work around that I mentioned earlier didn’t work. It only left me with the following failure during a full deployment:

Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx). at System.Guid..ctor(String g) at Microsoft.SharePoint.Deployment.FieldTemplateSerializer.ParseLookups(SPField fieldTemplate, ExportObjectManager objectManager) at Microsoft.SharePoint.Deployment.FieldTemplateSerializer.GetDataFromObjectModel(Object obj, SerializationInfo info, StreamingContext context) at Microsoft.SharePoint.Deployment.DeploymentSerializationSurrogate.GetObjectData(Object obj, SerializationInfo info, StreamingContext context) at Microsoft.SharePoint.Deployment.XmlFormatter.SerializeObject(Object obj, ISerializationSurrogate surrogate, String elementName, Boolean bNeedEnvelope) at Microsoft.SharePoint.Deployment.XmlFormatter.Serialize(Stream serializationStream, Object topLevelObject) at Microsoft.SharePoint.Deployment.ObjectSerializer.Serialize(DeploymentObject deployObject, Stream serializationStream) at Microsoft.SharePoint.Deployment.SPExport.SerializeObjects() at Microsoft.SharePoint.Deployment.SPExport.Run()

I am not sure if the two errors are related to the same source. However, it is interesting to know that the incremental job fails even when testing the job and the full deployment passes when tested. In the end, both deployment approaches fail. Leading me to beleive that the only option is to obtain the hotfix from Microsoft.

SPFolder and Content Approval

Question:How do I approve a folder in a document library that requires content approval using the SharePoint object model?

Answer:It may seem like a trivial question. After working with the SharePoint object model to create and approve files, it would make sense that any item or folder object would also contain methods needed to check in, publish, and approve them. Well after checking the members of the SPFolder and SPListItem classes on MSDN, I found that they don’t contain properties or methods to intuitively check in, publish, and approve them.

At first, I figured I could use the approve method from SPFile class since the folder object has a property to access the underlying item which has a a property to access the underlying file. Well, it turns out that file property of the item property of the folder object returns a null reference. So, I was back to square one.

As it turns out, the solution to this problem lies in working with the underlying item object. The underlying item object has a property that allows you to access the moderation information object (SPModerationInformation) which contains information about the approval status of the folder. You can then check the status and change as it needed by manipulating the moderation information object directly. Below is a method that I wrote to solve my problem (which was just to approve the folder):

private void ApproveFolder(SPFolder spFolder, SPDocumentLibrary spDocumentLibrary)
{
  if (spFolder.Exists && spDocumentLibrary.EnableModeration)
  {
    SPModerationInformation spModerationInformation = spFolder.Item.ModerationInformation;
    switch (spModerationInformation.Status)
    {
      case SPModerationStatusType.Pending:
        spModerationInformation.Status = SPModerationStatusType.Approved;
        spModerationInformation.Comment = "Got approval?";
        spFolder.Item.Update();
        break;
      default:
        break;
    }
    spModerationInformation = null;
  }
}

Obviously there is a lot more that you can do with the moderation information object. Hopefully, you will find my experience useful.

So You Want to Develop Custom SharePoint Workflows

Elaine Hao, Program Manager of SharePoint Workflow @ Microsoft, put together a really nice series of blog posts on developing MOSS2007 workflows on the Microsoft SharePoint Products and Technologies Team Blog. At the end of the series, she attached a little mini whitepaper that covers everything she covered in her series. I found it extremely useful as I worked on some custom workflow for a client and decided to keep a copy of So You Want to Develop Custom SharePoint Workflows for myself.

189 STSADM Operations

Jose Barreto blogged down all 189 STSADM.exe operations with their parameters for Microsoft Office SharePoint Server 2007 in his post, Complete reference of all STSADM operations (with parameters) in MOSS 2007. This is an indispensible reference, especially when you get errors in the Central Admin web interface that you can’t find a way around. As such, I decided to cut-and-paste them for myself. Continue reading “189 STSADM Operations”

Creating WSS Solution Packages for Microsoft Office SharePoint Server 2007

I am assuming you have done custom development for Microsoft Office SharePoint Server 2007. Whether it was a custom web part, workflow, event handler, feature, or module, at some point you probably had to figure out how to deploy it. If you are like me and learn a lot of what you know by doing, then you probably had to fiddle with web.config files and debugging errors with code access security exceptions. This post takes a stroll through a couple of ways to build and bundle a WSP file (a WSS solution package) and deploy it.

Before I begin, you should know that what assumptions I am making about the environment:

A Simple WSP Solution Package

I will update this post with a walk through of creating a simple WSP solution package using the Visual Studio 2005 extensions for Windows SharePoint Services 3.0 in the near future.