473,326 Members | 2,133 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,326 software developers and data experts.

xml file not being released

If this is the wrong newsgroup, appologies, and if you could tell me the
correct group to re-post to

I have a class that loads an xml file, and then navigates to to get a
description based on an id number. When I use this class on my asp.net
project ( not using the vs.net debugger ) the xml file is locked and is not
released until I restart the web service. I am sure that I have missed a
step in regards to releasing the xml file when I am finished.

If anybody could point out my mistake, would be great.

Thanks in advance.

Darren.

This is my class

public class GetError
{
int _Code;
string _Desc;
string _FileName;
XmlTextReader reader;
XmlDataDocument xml_data;
/// <summary>
///
/// </summary>
/// <param name="filename">The file to open, and the xml element
name</param>
public GetError(string filename)
{
_FileName = filename;
reader = new
XmlTextReader(System.Web.HttpContext.Current.Serve r.MapPath("/WebAssist/Constants/"
+ _FileName + ".xml"));
xml_data = new XmlDataDocument();
xml_data.Load(reader);
}
/// <summary>
/// The error code that was looked up
/// </summary>
public int Code
{
get { return _Code; }
set
{
_Code = value;
GetErrorDesc();
}
}
/// <summary>
/// The actual error description
/// </summary>
public string Description
{
get { return _Desc; }
}
/// <summary>
/// ToString representation. Code + Description
/// </summary>
/// <returns></returns>
public override string ToString()
{
return _Code.ToString(CultureInfo.CurrentCulture) + " - " + _Desc;
}
/// <summary>
/// based on the code supplied, get the description
/// </summary>
void GetErrorDesc()
{
_Desc = string.Empty;
XPathNavigator nav;
nav = xml_data.CreateNavigator();
XPathExpression expr;
expr = nav.Compile("descendant::" + _FileName + "[id=" +
_Code.ToString(CultureInfo.CurrentCulture) + "]");
XPathNodeIterator itr;
itr = nav.Select(expr);
itr.MoveNext();
XPathNavigator nav2 = itr.Current.Clone();
nav2.MoveToFirstChild();
nav2.MoveToNext();
_Desc = nav2.Value;
}
}



Nov 12 '05 #1
2 1172
"Darren Guy" <da********@no.spam.idesk.com> wrote in message news:Ol*************@TK2MSFTNGP12.phx.gbl...
project ( not using the vs.net debugger ) the xml file is locked and is not released until I restart the web service. I am sure
that I have missed a step in regards to releasing the xml file when I am finished. : : reader = new XmlTextReader(System.Web.HttpContext.Current.Serve r.MapPath("/WebAssist/Constants/" + _FileName + ".xml"));


I can make two observations here.

First, reader is a field of the GetError class. Ask yourself how long objects
of the GetError class live and when they dispose of their resources? I never
see you call Close( ) on the XmlTextReader anyplace. Consider having the
GetError class implement IDisposable, and when implementing the Dispose
method make sure that you call Close( ) on reader.

Second, you pass a filename to the XmlTextReader. It may be clearer as to
when the FileStream gets freed up from its exclusive lock if you break it out
into a separate FileStream variable. You'd still construct reader around a
StreamReader (aka TextReader) for your FileStream, but this way you're
more conscious of having to close the FileStream and dispose of it.

It's probably the first issue - that Close( ) is never called on reader.
Derek Harmon
Nov 12 '05 #2
Derek

the problem was that I was not calling the close on the reader. I know I had
missed something simple.

So I changed my class inherit from IDisposable, and implemented a Dispose
function that closes the reader.
I also created a Close method that closes the reader.

Thanks again
Darren
Nov 12 '05 #3

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

Similar topics

6
by: John Reese | last post by:
def uselessHash(filename): fp= open(filename) hash= 0 for line in fp: hash ^= hash(line.strip()) fp.close() # do I need this or is fp closed by ref count? return hash Consider the function...
9
by: Paul | last post by:
Hi, VB.NET is saying the file I am creating is in use by another process and won't complete its task of moving the file to the specified destination folder. Here is my code (the main bit...
3
by: Ramesh K | last post by:
Hi All, During Attach to a process like DLLHOST ,DLLHOST has FILE references to the system dlls like " odbc32.dll etc..(One can observer this in process explorer tool of Sysinternals.com by...
18
by: Conrad F | last post by:
Hello all, I am waiting for receipt of files in a directory. I use the FileSystemWatcher to detect when files arrive in said folder. I need to read the data from these files ASAP but the files...
6
by: Don | last post by:
I'm having problems working with a streamwriter object. After closing the streamwriter and setting it to Nothing, I try to delete the file it was writing to, but I always get the following error...
1
by: Daniel | last post by:
does the windows file handle change? are file handles unique to the whole operating system or just the current directoy? if a file is opened then closed then opened again, does the file handle...
5
by: Nick Z. | last post by:
When using SmtpClient and sending a message with an attached file using SendAsync(...), if I add File.Delete(pathToAttachedFile) in the SendCompleted event handler I get a file in use exception. Is...
9
by: Tristán White | last post by:
Hi I am very new to PHP - actually, this is my second day at it, as I've only recently started a new job last week. We're a charity. I have a "No input file selected" problem. A Google search...
1
by: sherihan2007 | last post by:
when the drw file is released the associated prt files should also get released but it is not happening ....can anyone helpe me out of this
5
by: Andrew Cooper | last post by:
I posted this before but apparently it was eaten by the great Internet gods. I've got an application that watches a file. When that file is changed the application reads the data on the file...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...

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.