New thread - not same credentials?

  • Thread starter Thread starter Casper Hornstrup
  • Start date Start date
C

Casper Hornstrup

I upload an excel file, save it on the webserver and import the contents to
an MSSQL database.
I use the MS JET OleDb provider to read from the excel file. If I do this
during the HTTP
request this works fine. If however I let another thread (from a pool I've
created when
the ASP.NET application was first started) do the job, the OleDb provider
returns E_FAIL.
If I give Everyone full rights on the file, it works when the new thread is
used.
This is on a Windows Server 2003 btw. When the file is uploaded, it receives
Special (Allow List folder / Read data, Allow Delete) for NETWORK SERVICE.
The ASPNET user is not in the ACL. How can I solve this problem?

Casper
 
It should not be working for you at all. Well at least, that's the mind set
you should have because you've violated a major thread law here. Threads are
not allowed to tamper with objects belonging to the main thread. The main
thread owns the http object, your worker thread does not. Results will
typically be flakey, working sometimes, failing at others because of the way
requests are scheduled underneath the hood.

To work around this, you can try passing a reference to the http object to
the worker thread. This will allow the worker thread to safely modify the
object and guarantee consitency. So from the pool of threads you created,
let one of the parameters be a httpcontext object.
 
Back
Top