473,385 Members | 1,355 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Locking XML/Corruption problems

Followup to a previous related topic now that I have a few more details.

We've been having issues with part of our home-grown CMS.

Whenever a page is edited, and saved, we do a recursive call to the DB and
then spit out an XML file to build the site map, which is then published to
the site.

We ran into an issue that we believe (as we can't replicate it) is happening
when two people manage to hit SAVE at the exact same time, causing two
processes to try writing to the exact same XML file at the same time. This
appears to cause the XML file to only be half-written (my theory that the
second process interupts the first and then they both fail).

This is what we originallly had:

objXMLWriter = New
System.xml.XmlTextWriter(System.Web.HttpContext.Cu rrent.Server.MapPath("/mjb05/xml/"
& siteID & "/siteMenu.xml").ToString, Nothing)

It was suggested that we lock the file as we write it, preventing any
further edits from another process until the first process is done with it:
Dim fs As New
System.IO.FileStream(System.Web.HttpContext.Curren t.Server.MapPath("/mjb05/xml/"
& siteID & "/siteMenu.xml").ToString, IO.FileMode.Open, IO.FileAccess.Write,
IO.FileShare.Read)
objXMLWriter = New System.xml.XmlTextWriter(fs, Nothing)

However, this causes a new problem. Not every time, but usually every other
time or so, when the XML is written, the entire XML file is written
correctly, but then some 'extra crap' is tacked onto the end...typically a
repeat of a few nodes split in the middle of a tag. Which, obviously, is
causing the XML that is being written to be invalid.

Any thoughts on what is happening and/or why and/or a fix/workaround?

The only thing I've been able to come up with is to have the function write
the XML, and then use another function to open the file back up again, and,
then using some string functions, trim off anything after the last closing
node, then resave. That, of course, is a huge hack, so less than idea.

I've also discovered that the problem ONLY happens when i do the recursion.
If I just run through the function once, I can not get it to write the bad
XML. Not sure HOW that is related, but it's something else I've been able to
observe.

Any thoughts appreciated!

-Darrel


Apr 6 '06 #1
2 970
Sorry, but it looks like a logic problem. Create a stand-alone VB.NET
app that uses the same logic that writes to your local file system, and
attempt to diagnose. I really doubt that it is "two people at the exact
same time". If it happened more than once, that is impossible.

Apr 6 '06 #2
Sorry, but it looks like a logic problem. Create a stand-alone VB.NET
app that uses the same logic that writes to your local file system, and
attempt to diagnose. I really doubt that it is "two people at the exact
same time". If it happened more than once, that is impossible.


It happened twice. And you are right, no guarantee what, exactly, happened.
As there's no way for us to replicate it.

But, neither here or there...we should be locking the file anyways.

Regarding my current problem with a 'corrupted' XML file, I *FINALLY*
realized what was going on:

Every time I changed the database, and spit out a new XML file, the total
length of the XML file would change. As long as my DB data was INCREASING,
the resultant XML file would be longer than the previous and completely
overwrite the old data.

HOWEVER, if I did anything to REDUCE the amount of data in my DB, the
resultant XML file would be shorter than the previous one written. As such,
it would just 'leave' whatever extra bit of info was there in the file the
last time. We didn't notice this until recently, as most updates were
increasing the DB size (since we're in a massive content migration phase).

IOW, if my XML file is 900 characters long, and I update the DB so the next
XML file is 1000, everything is fine. Then I make another update and reduce
the file to 980 characters. At that point, it dumps all 980 characters back
to the XML file, but leaves those last 20 characters of the previous file,
thereby corrupting it.

Fix? I need to delete the file first and create a brand new, blank file.

WHEW! That was a stumper. ;o)

-Darrel
Apr 6 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Noa Garnett | last post by:
I'm developing on C++, using visual studio 6.0 with service pack 5. I have a memory corruption while debugging. Some of the variables I'm using are suddenly set to zero while progressing along the...
7
by: Fred MacMurray | last post by:
Hello, all. So we're all happy with Access. Or Access is "good enough" with most of our applications. I built a split database here at work that has about seven users who are on pretty much...
26
by: jamesbeswick | last post by:
I've been using Access since version 97 and I've migrated to 2003. I've noticed a substantial number of strange ActiveX/OLE and code corruption problems when writing databases. The only solution...
23
by: Dave G | last post by:
Since upgrading one of my clients from A97/W2000 to A2003/XP they have suffered no end of data corruption problems, mainly involving one of the main tables. The corruption can result in one...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.