How to ignore "The process cannot access the file because it is being used by another proces"

1

The setup is this:

Whenever an error occurs on my website, an error-site is being displayed while an e-mail is being sent to the administrator.

The website show a lot of live statistics automaticly updated every 15 second via AJAX and XML. But the statistics are only calculated once every 15 second, no matter how many users there is. This is done by a timestamp hidden ind the MSSQL database:

  • The website check if the timestamp is older than 14 seconds
  • If it is, then it updates the timestamp and runs the calculation of the stats and saved them to XML
  • At last the XML are being looped through and showing the requested stats to the users

IF the timestamp is NOT older than 15 seconds, the second step is being skipped.

Now my problem is, that if 2 users makes the timestamp request at the same time then the system doesn't have the time to update the timestamp before both of the users tries to update the XML document, causing one of them to fail with the error message:

msxml3.dll (0x80070020)
The process cannot access the file because it is being used by another process.
/file.asp, line 310

Is it possible to check if the process is being used BEFORE trying to save the XML document? Or maybe ignoring this explicit kind of error?

xml
sql-server-2008
asp-classic
asked on Stack Overflow Nov 4, 2012 by MicBehrens • edited Nov 5, 2012 by MicBehrens

2 Answers

1

I think that a simple lock will solve your issue.

In classic ASP lock can be achieved using the Application object by setting top level application variable.

In the code running the calculation make those changes:

If Application("Calculation_Lock")<>"" Then
    Application("Calculation_Lock") = Now()
    'do the calculation...
    'calculation in progress...
    'calculation in progress...
    'calculation in progress...

    'when it's all done:
    Application("Calculation_Lock") = ""
End If

Initially, the application level variable will be empty so the first user will enter the If statement, then assign the lock. Any further requests will be ignored while the lock is active i.e. the application level variable is set.

There is risk of the lock staying active forever in case of error during calculation, so to play it safe you can compare the value (which is the time when the lock was set) and the current time and if more than X seconds/minutes passed manually release the lock.

0

Move away from the database with timestamps.

Check out the code here; simply set the duration to 15 seconds and see if that does as you want things to happen.

answered on Stack Overflow Nov 4, 2012 by mabako • edited Jan 18, 2021 by Community

User contributions licensed under CC BY-SA 3.0