Click to See Complete Forum and Search --> : File In Use
Exuro
05-28-2004, 04:24 PM
I'm having a problem with an XML file being used by an XmlFileReader in an ASP.Net page of mine. After the page is viewed once, the file is "locked" because it is "in use by another process". I cannot overwrite or delete the file unless I kill the aspnet_wp.exe process, which is a pain.
As an attempt to get around this I tried to write to the XML file through ASP.Net (since that's obviously the process that is using the file), but it gives me this error:
The process cannot access the file "news1.xml" because it is being used by another process.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.IO.IOException: The process cannot access the file "news1.xml" because it is being used by another process.
Source Error:
Line 27: newEntry.AppendChild(newMessage);
Line 28: root.PrependChild(newEntry);
Line 29: newsDoc.Save(Server.MapPath("news1.xml"));
Line 30: }
Line 31: else {
Does anyone know how to stop ASP.Net from constantly having the XML file locked up???
PeOfEo
05-31-2004, 03:08 PM
huh, that is pretty odd. I have never had a problem like this with an xml file because xml is just an ascii text file. What is the server os, I am assumeing it is asp.net 1.1 on iis.
Exuro
05-31-2004, 07:47 PM
WinXP Pro
IIS v5.1
ASP.Net v1.1
PeOfEo
05-31-2004, 09:43 PM
This could be an issue with simple share (but I doubt it). Is simple share turned off on your machine?
Exuro
06-02-2004, 08:11 PM
Sorry I took so long to respond, I didn't realize anyone had replied for some reason...
Simple file sharing is turned off on my machine, so that isn't the issue. I'm 99.9% sure that it's the ASP.Net process that is locking it up since it only locks up after I view the page I parse the XML document on, and then it stays locked until the aspnet_wp process is manually ended or I restart my computer. I'm really confused on this :(
Exuro
06-23-2004, 01:04 PM
I finally fixed it!
As it turned out the problem ended up being in this line of code:
oldDoc.Load(new XmlTextReader(Server.MapPath("news1.xml")););
The XmlTextReader object being created within the Load method of the XmlDocument was locking up the file because it was not being closed. I had just assumed since the XmlTextReader was being created within a method that it would go out of scope and automatically close. Apparently though, this assumption was wrong. So doing the following fixed it:
XmlTextReader reader = new XmlTextReader(Server.MapPath("news1.xml"));
oldDoc.Load(reader);
reader.Close();
blamm
05-18-2005, 03:55 PM
I have a similar problem, except that it is locking the xml file in these lines..
TREENODES.TreeNodeSrc = Server.MapPath("tree.xml");
TREENODES.DataBind();
Please help, as it locks the xml file, and then i have to kill the aspnet_ws process to get access to the xml file...
Thanks a lot in advance.
Blamm
Exuro
05-20-2005, 10:46 PM
Is that ADO.Net that you're using? Do you ever release the file after you bind it to your table? If not, that's probably the problem. Look into the documentation for the XML database functions you're using (whatever they may be), find out how to close/release the file, and make sure that you include the necessary code to do so at the end of your script.
CardboardHammer
05-24-2005, 10:24 AM
Never, ever, depend on objects being automatically cleaned up when going out of scope in .NET. The automatic cleanup only happens when garbage collection happens, which, unless you explicitly trigger it, may be a very long time in coming about.
Typically, resources should be acquired no sooner than needed and be explicitly released as soon as no longer needed.
blamm
05-24-2005, 01:55 PM
Hey thanks so much for replying. Can you tell me where can I find xml database functions. Not sure what that means. I tried TREENODES.Dispose() to release resources, but did not help. Any idea????
blamm
05-24-2005, 01:56 PM
I know that somewhere I am not releasing the xml file, I am just not able to figure out where and how....
Please help!
Exuro
05-24-2005, 02:09 PM
I think this is where I got the examples I based my XML data reader off of:
http://samples.gotdotnet.com/QuickStart/howto/default.aspx?url=/quickstart/howto/doc/xml/overviewofxml.aspx
blamm
05-24-2005, 02:15 PM
I am not using any XMLTextReader to read the file. The IE Treeview control is reading the xml file. And somewhere its not releasing it back.
Any idea?
blamm
05-26-2005, 02:07 PM
Well got it.. Its the Server.MapPath that was locking the file..
I gave relative path "XML\tree.xml" and it worked fine...
Thanks all..