tirsdag den 12. marts 2013

Sharepoint Document cheked out to

I wass asked to make a blog on an topic that was related to the checked out to <none> problem.
When SharePoint gets a deadlock in relation to Check-In/Check-Out situation it is due to the state of the CheckOutUserID field in the AllDocs table.

This field is set to -1, which by SharePoint is interpreted as <none>

To fix the page and thus be able to check-in or -out the page the CheckOutUserID must be replaced by an existing UserID from that particular Site Collection/Web Application.

The below SQL script does that, however it is important, that one item exist in the list in addition to the broken one, as the ID used in the script below, will be taken from the first item having an ID different from -1.
Alternative Microsoft advice to use the ID "58"

Generic script below, only the Database name is needed prior to running this.

USE [Portal_XXX_content]
GO
BEGIN TRY
BEGIN TRANSACTION
-- Check if any documents checked out with an invalid status
IF (SELECT COUNT(*)
FROM AllDocs (NOLOCK)
WHERE CheckoutUserId = -1) <= 0
BEGIN
PRINT 'INFO: No document checked out with invalid user id (-1)'
END
ELSE
BEGIN
-- Check if any checked out documents available
IF (SELECT COUNT(*)
FROM AllDocs(NOLOCK)
WHERE CheckoutUserId IS NOT NULL
AND CheckoutUserId > -1) <= 0
BEGIN
PRINT 'ERROR: Nothing checked out so can''t find a valid user ID'
END
ELSE
BEGIN
-- Show documents that has invalid user id
SELECT *
  FROM AllDocs(NOLOCK)
  WHERE CheckoutUserId = -1
  --Updating sharepoint field [checkoutUserId] to a value different from -1
  UPDATE [AllDocs]
  SET CheckoutUserId = (SELECT TOPCheckoutUserId
                        FROM [AllDocs] (NOLOCK)
                        WHERE CheckoutUserId > -1)
WHERE CheckoutUserId = -1


SELECT *
  FROM AllUserData (NOLOCK)
  WHERE tp_CheckoutUserId = -1
  --Updating sharepoint field [tp_CheckoutUserId] to a value different from -1
  UPDATE [AllUserData]
  SET tp_CheckoutUserId = (SELECT TOP 1 CheckoutUserId
                           FROM [AllDocs] (NOLOCK)
                           WHERE CheckoutUserId > -1)
  WHERE tp_CheckoutUserId = -1
END
END
--Finish SharePoint update
PRINT 'The operation completed successfully.'
COMMIT TRANSACTION
END TRY
BEGIN CATCH
IF XACT_STATE() <> 0
BEGIN
ROLLBACK TRANSACTION
END
DECLARE @ErrorInfo NVARCHAR(4000)
SELECT @ErrorInfo = ERROR_MESSAGE()
RAISERROR(@ErrorInfo, 16, 1)
END CATCH

This Solution is supported by Microsoft!

Ingen kommentarer:

Send en kommentar