[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 688
  • Last Modified:

ASP.Net: global.asax generic error handling - Can it close an open file?

On our site, we use global.asax's Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs) to catch pretty much all errors thrown. Right now, this sub sends an email with error details. We wish it to stay that way, that is, we don't wish to start using lots of try/catch blocks. Errors, when they occur, have to be studied and fixed so they don't happen again.

However, there are a couple pages where the user can upload a text file, which is then imported into the DB. When an error occurs, the uploaded file becomes locked and can't be moved/deleted until IIS decides to release it (not sure how long that takes, but it's too long).

We can resume the procedure in 3 steps:
1- Open the file
2- Read the file and use those values
3- Close the file

When an error occurs on step 2, the file is then locked. So, is there any way for global.asax's sub to close the file?
0
Cluskitt
Asked:
Cluskitt
  • 2
  • 2
1 Solution
 
CodeCruiserCommented:
Not unless you dispose the reader which has opened the file. I think you may need to use try catch in this instance. What you can do is rethrow the exception so your global code still works

Try
   'code to process file
Catch Ex As Exception
   'code to release file
   Throw New Exception("Rethrowing", ex)
End Try
0
 
CluskittAuthor Commented:
I was mostly wandering if there was a way to send the reader as a parameter. Or, if it would be feasible to set it as a global object (which would allow global.asax to close it)
0
 
CodeCruiserCommented:
Parameter would not be possible I think. Global variable is possible but I would prefer the technique shown above.
0
 
CluskittAuthor Commented:
Thanks.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now