Corrupt WebConfigModifications in SharePoint

Search

Accessible SharePoint WebSites
Download ARF

Corrupt WebConfigModifications in SharePoint

http://blog.thekid.me.uk

I have been trying out different values for SPWebConfigModification properties and in doing so I managed to corrupt the SPWebConfigFileChanges persisted class. This class manages the updates to web.config and persists itself to the SharePoint_Config database.

In trying out different property values I hit one that was accepted, but it caused some kind of corruption. It appears the WebConfigChildNodes property of SPWebConfigFileChanges contained an invalid node and that resulted in receiving the following error everytime I tried to update the application (using ApplyWebConfigModifications).

The node to be removed is not a child of this node.

Because the SPWebConfigFileChanges is persisted, a simple IISRESET did not clear the problem and I couldn't find a way to remove the offending item either through code or debugging. I was forced to look into the configuration database to fix the problem.

Ordinarily I would not recommend modifying the SharePoint database directly, but when there is no other way you are left with little choice.

To fix this problem you need to find the entry for the SPWebConfigFileChanges object causing the problem and change it. This can be found in the Objects table of the SharePoint_Config database. The following SQL should help with that.

 

SELECT    Id, ClassId, ParentId, Name, Status, Version, Properties

FROM        Objects

WHERE    (Name LIKE '%WebConfig%')

 

You will need to look at the Properties column, which contains the XML for the persisted object. Once you have identified the offending item you will need to modify it, but in order to modify this table you will need to disable the triggers (right-click on each trigger and select disable). Once the two triggers are disabled perform an IISREST (to make sure the object is not in memory) and you will then be able to modify the Properties column.

Copy the entire contents of the properties column to your favorite XML editor and remove the the entry you believe to be causing the problem, then copy it back. Alternatively you can delete the entire row (as I did), but this means you may cause further problems if other changes exist. Restore the triggers and try to execute the code which was causing the problem.

This should prevent the exception and allow the code to continue.

Posted by Vincent Rothwell on Friday, 23 Mar 2007 22:30  - 6 Comments
Orininally printed from http://thekid.me.uk - Copyright Vincent Rothwell 2007
 

Comments

Sunday, 27 Jul 2008 10:36 by mark
Hi there. I've been searching the web for help with a particular problem I've come across in web.config. Maybe you can help me. I was in the web.config file the other day. I was trying to fix a web part time-out. According to instructions I had, I had to look for the line with "webpartworkitem" in it, and then change the timeout value. I eventually found the line andchange a value from 5000 to 9000. I saved the file and ran iisreset. Then I realised that the 5000 was actually part of the version number in that string, so I changed the 9000 back to 5000, saved, and then reran iisreset. After this I was getting a server error. It actually had nothing to do with the change I made at least, nothing to do with directly). Upon closer examination, the error was caused by a line with a ? in it.That is, there was one string with the word "Name?ype". The error indicated that his was wrong. (I hadn't touched this line, so, in theory, it must have been there already". I changed the value to "Nametype". Saved & iisreset. Now SharePoint returned an error, that, after investigation, seemed to be caused by the SPS. After looking ta the web.config again, I found several lines where a "?" was being used instead of the correct letter (e.g. "asp?", "name?ype", "23T33?8"). I changed all the "?" to the correct value, and then the MOSS app ran fine. But I'm not sure why the question marks were present? Any ideas? Many Thanks

Sunday, 27 Jul 2008 10:36 by søren
Phew! You saved my day. Fiddled around with a feature that needed to add a childnode with subnodes to the web.config file. It's not properly supported, and my small tests eventually completely removed SharePoints ability to modify web.config (and interestingly not just the web app I was working on, but all) /Søren

Sunday, 27 Jul 2008 10:37 by Marc Reynolds
I just had a similar problem with a corrupted web config modification being persisted, but I had no chance of getting to the database because of security. I did find a way to remove faulty modifications through the object model, though. The trick is to remove the SPWebConfigModification from the web app, call update on the web app, then get a reference to the SPWebService and update that as well. I just cleared out all modifications on the problem web app, but my guess is that you could simply remove bad ones (if you can find them). Here's a sample execution I ran from the immediate window: webApp.WebConfigModifications.Clear() Expression has been evaluated and has no value webApp.Update() Expression has been evaluated and has no value webApp.Farm.Servers.GetValue<SPWebService>().ApplyWebConfigModifications() 'webApp.Farm.Servers.GetValue<SPWebService>().ApplyWebConfigModifications()' threw an exception of type 'System.Xml.XmlException' base {System.SystemException}: {"The '[' character, hexadecimal value 0x5B, cannot be included in a name. Line 1, position 166."} LineNumber: 1 LinePosition: 166 Message: "The '[' character, hexadecimal value 0x5B, cannot be included in a name. Line 1, position 166." SourceUri: "file:///***/8080/web.config" webApp.Farm.Servers.GetValue<SPWebService>().WebConfigModifications Count = 0 webApp.Farm.Servers.GetValue<SPWebService>().Update() Expression has been evaluated and has no value webApp.Farm.Servers.GetValue<SPWebService>().WebConfigModifications Count = 0 webApp.Farm.Servers.GetValue<SPWebService>().ApplyWebConfigModifications() Expression has been evaluated and has no value

Tuesday, 19 Aug 2008 10:30 by martin
:) What to say ? THANKS

Wednesday, 10 Sep 2008 02:32 by Michael
This was a life saver - excellent, thanks forsharing this!

Friday, 23 Oct 2009 08:58 by mikee
thank you admin:)wonderful..



Url

Email

Comments