File locked by another process when cached with CacheDependency

Ask a Question related to ASP.NET Web Services, Design and Development.

  1. #1

    Default File locked by another process when cached with CacheDependency

    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 Guest

  2. Similar Questions and Discussions

    1. file locked but there's no .LCK
      "you can't edit this page because you are currently editing it on another computer", says contribute. And I know for sure I'm not. I know all...
    2. How to recognize the locked PDF-file?
      Hello! I need to overload the standard Acrobat message that the document is opened by another application which appears on saving the document....
    3. help: File is locked
      Could anyone help me with this? I created a vector image file a couple of days ago, when I made some changes today, and tried to save it, Fireworks...
    4. File Locked
      Everytime I try to save an image to html with slices I get a file locked error. If I get rid of the slices there is no problem. I checked other file...
    5. A failure occurred writing to the resources file. Access is denied. -- RESX file is locked? -- WHY?
      Hi. This is an error that comes up fairly regularly when trying to run the "Rebuild All" command in a Solution that contains more than one...
  3. #2

    Default RE: File locked by another process when cached with CacheDependency

    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! [url]www.microsoft.com/security[/url]
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)

    MSFT Guest

  4. #3

    Default Re: File locked by another process when cached with CacheDependency

    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 Guest

  5. #4

    Default Re: File locked by another process when cached with CacheDependency

    Thanks, Your guide help me also
    I used the file stream for my xmldocument.

    my code is:

    //Open and read the textfile
    XmlDocument D = new XmlDocument();
    FileStream fs = new FileStream(FN, FileMode.Open, FileAccess.Read);
    D.Load(fs);

    ....
    //this line solved my problem
    fs.Close();
    Unregistered Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139