Impersonate in ThreadPool

V

Viorel Ghilas

Hi all

I have an ASP.NET application that uses impersonate account to connect to
DB, this works good. But in some cases I need to put some methods in
ThreadPool. The methods from ThreadPool should do some foreground operations
with DB. But .NET throws me the sql exception "Login failed for user
'(null)'. Reason: Not associated with a trusted SQL Server connection.". The
thread from pool in execution proccess has an ASPNET account different from
my impersonated account. How can I resolve this problem, do you have any
suggestions?

with best regards
Viorel
 
A

Alvin Bruney [MVP]

It is not resolvable in .NET currently. The spawned thread assumes the
identity of the calling process. I'm not aware of a fix for this situation.

--
Regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
The Microsoft Office Web Components Black Book with .NET
Now Available @ http://tinyurl.com/27cok
 
V

Viorel Ghilas

Hi, I found the solution.It is simple

in state parameter in WaitCallBack I send WindowsIdentity.GetCurrent()

in method I use WindowsImpersonationContext from identity.Impersonate()
do some code than context.Undo()

it's simple and elegant

thx all

Alvin Bruney said:
It is not resolvable in .NET currently. The spawned thread assumes the
identity of the calling process. I'm not aware of a fix for this situation.

--
Regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
The Microsoft Office Web Components Black Book with .NET
Now Available @ http://tinyurl.com/27cok
----------------------------------------------------------


Viorel Ghilas said:
Hi all

I have an ASP.NET application that uses impersonate account to connect to
DB, this works good. But in some cases I need to put some methods in
ThreadPool. The methods from ThreadPool should do some foreground
operations
with DB. But .NET throws me the sql exception "Login failed for user
'(null)'. Reason: Not associated with a trusted SQL Server connection.".
The
thread from pool in execution proccess has an ASPNET account different
from
my impersonated account. How can I resolve this problem, do you have any
suggestions?

with best regards
Viorel
 
A

Alvin Bruney [MVP]

would you mind posting the relevant portions of the code?

--
Regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
The Microsoft Office Web Components Black Book with .NET
Now Available @ http://tinyurl.com/27cok
----------------------------------------------------------


Viorel Ghilas said:
Hi, I found the solution.It is simple

in state parameter in WaitCallBack I send WindowsIdentity.GetCurrent()

in method I use WindowsImpersonationContext from identity.Impersonate()
do some code than context.Undo()

it's simple and elegant

thx all

Alvin Bruney said:
It is not resolvable in .NET currently. The spawned thread assumes the
identity of the calling process. I'm not aware of a fix for this situation.

--
Regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
The Microsoft Office Web Components Black Book with .NET
Now Available @ http://tinyurl.com/27cok
----------------------------------------------------------


Viorel Ghilas said:
Hi all

I have an ASP.NET application that uses impersonate account to connect to
DB, this works good. But in some cases I need to put some methods in
ThreadPool. The methods from ThreadPool should do some foreground
operations
with DB. But .NET throws me the sql exception "Login failed for user
'(null)'. Reason: Not associated with a trusted SQL Server
connection.".
The
thread from pool in execution proccess has an ASPNET account different
from
my impersonated account. How can I resolve this problem, do you have
any
suggestions?

with best regards
Viorel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top