locked
XmlDataSource: The process cannot access the file because it is being used by another process RRS feed

  • Question

  • User1196439756 posted

    Ok so a little bit of background information before I ask my question. I have a desktop application that runs on my web server which writes xml files to an IIS directory every 5 seconds (The files are very small). So every 5 seconds each xml file is overwritten with new, fresh data. I use these xml files to bind 2 gridviews and a datalist on an asp.net webpage via XmlDatasource controls. This page is kind of like a "live feed" for my users so I have placed a Timer control inside an AJAX UpdatePanel that refreshes the gridviews and datalist every 5 seconds...I should also mention that I am setting the XMLDataSource.DataFile property on Page_Load according to the user's session value:

    For example: FeedXDS.DataFile = "~/xml/" & Session("XmlGUID").ToString() & ".xml"

     

    The problem is that I perodically get the following error:

    The process cannot access the file 'C:\Webs\MySite\xml\7b7c972f-9545-4738-b5dc-b5ea00d21901.xml' because it is being used by another process.

    I assume what is happening is the desktop application is trying to write the file while IIS is trying to read the file at the exact same time. How can I wrap the automatic databinding in a try catch statement?

     

    Saturday, March 15, 2014 12:29 AM

Answers

  • User-821857111 posted

    I think what I would do is the following in code behind (in pseudo-code):

    try
        see if a file exists
        read XML file content
        deserilaise it using LINQ to XML
        cache it
        delete the file
    catch
        don't do anything

    GridView.DataSource = cached data 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, March 15, 2014 5:41 AM

All replies

  • User-821857111 posted

    I think what I would do is the following in code behind (in pseudo-code):

    try
        see if a file exists
        read XML file content
        deserilaise it using LINQ to XML
        cache it
        delete the file
    catch
        don't do anything

    GridView.DataSource = cached data 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, March 15, 2014 5:41 AM
  • User1196439756 posted

    So get rid of the XMLDataSources completely? Will this cause a performance hit and be slower using LINQ to query the xml as opposed to a XmlDataSource and XSLT to bind controls?

    Saturday, March 15, 2014 12:12 PM
  • User-821857111 posted

    So get rid of the XMLDataSources completely?

    Yes. Define an entity to represent the XML and bind a collection of that to the GridView.

    Will this cause a performance hit and be slower using LINQ to query the xml as opposed to a XmlDataSource and XSLT to bind controls?

    Either way the XML structure is traversed and converted into a form that can be bound to the GridView. Linq might be slower or quicker. I don't know. It's not something that would worry me unduly.

    Saturday, March 15, 2014 2:25 PM
  • User1196439756 posted

    Thank you for the suggestion. This seems to be working quite well so far!

    Saturday, March 15, 2014 4:19 PM