Tuesday, November 16, 2010

How to repair corrupt SPWebConfigModification Objects in SharePoint?

Scenario: How to repair corrupt SPWebConfigModification objects?

Explanation: Recently I worked on automating web.config deployments through PowerShell and during that process, I have ended up corrupting the SPWebConfigModification objects several times.

An indication of corrupted SPWebConfigModification objects is the generic exception "Object reference not set to instance of an object" when you try to make any changes to web.config using SPWebConfigModification class from code.

The below steps could be followed to fix the corrupted SPWebConfigModification objects:

Navigate to the table "Objects" in database "SharePoint_Config" and run the below script:

SELECT    Id, ClassId, ParentId, Name, Status,  Version, Properties
FROM        Objects
WHERE    (Name LIKE '%WebConfig%') 

In order to make any updates this table, we will need to disable the triggers on it.
By default,  the table "Objects" has the following triggers attached to it:
  • trigger_OnDeleteObjects
  • trigger_OnTouchObjects


DISABLE TRIGGER [dbo].[trigger_OnDeleteObjects] ON Objects
DISABLE TRIGGER [dbo].[trigger_OnTouchObjects] ON Objects

Perform an IISRESET.

Identify the corrupted row and delete it.

I have also tried to modified the corrupted item but it did not work
out. 

Enable triggers on the Objects table:

ENABLE TRIGGER [dbo].[trigger_OnDeleteObjects] ON Objects
ENABLE TRIGGER [dbo].[trigger_OnTouchObjects] ON Objects

Reference: thekid.me.uk

No comments:

Post a Comment