File locked by another process when cached with CacheDependency

Discussion in 'ASP .Net Web Services' started by Keith, Oct 1, 2003.

  1. Keith

    Keith Guest

    Hi.

    I've developed an ASP.NET web service that uses an xml file to store
    configuration settings. I'm creating a cache dependency based on the xml
    file and its schema, like this...

    XmlDocument doc = new XmlDocument();
    { ........ }
    string [] filePaths = { filePath, schemaPath };
    CacheDependency dep = new CacheDependency(filePaths);
    Context.Cache.Insert(key, doc, dep);

    The problem is the files are being locked by another process. I'm assuming
    they're locked by the aspnet_wp process, because if I run iisreset, the
    files are free until the next time the web service is called.

    I'd like to be able to update the files without having to reset the server
    each time. I'd expect the cached item would then be cleared from cache, so I
    can reload it with the newer version of the xml document.

    The documentation for HttpContext.Cache says this is possible, but it's not
    working.

    Thanks in advance.

    -|<eith.
    Keith, Oct 1, 2003
    #1
    1. Advertising

  2. Keith

    MSFT Guest

    Hi Keith,

    Each application domain has its own Cache object. If your XML file was
    cached by an app, you must remove it from cache so that it can be reused,
    like:

    HttpContext.Cache.remove("key1")

    Luke
    Microsoft Online Support

    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)
    MSFT, Oct 2, 2003
    #2
    1. Advertising

  3. Keith

    Keith Guest

    I found the answer to my problem. I wasn't closing my XmlValidatingReader
    object. Duh! Thanks for your help Luke.

    -|<eith

    ------------------------------------------
    string filePath = Server.MapPath("ParamConfig.xml");
    string schemaPath = Server.MapPath("ParamConfig.xsd");
    // open, validate and cache config file.
    XmlTextReader xtr = new XmlTextReader(filePath);
    XmlValidatingReader xvr = new XmlValidatingReader(xtr);
    XmlTextReader sxtr = new XmlTextReader(schemaPath);
    xvr.Schemas.Add(null, sxtr);
    doc = new XmlDocument();
    doc.Load(xvr);

    // THIS LINE SOLVED THE PROBLEM
    xvr.Close();

    string [] filePaths = { filePath, schemaPath };
    CacheDependency dep = new CacheDependency(filePaths);
    Context.Cache.Insert(key, doc, dep);
    ------------------------------------------
    Keith, Oct 2, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Keith
    Replies:
    0
    Views:
    520
    Keith
    Oct 1, 2003
  2. Craig G
    Replies:
    0
    Views:
    381
    Craig G
    Mar 7, 2005
  3. Weston Weems
    Replies:
    0
    Views:
    441
    Weston Weems
    May 27, 2005
  4. TJO
    Replies:
    3
    Views:
    721
  5. Felipe
    Replies:
    1
    Views:
    332
    Laurent Bugnion
    Aug 11, 2006
Loading...

Share This Page