473,382 Members | 1,646 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Simple thread issue?

I have an file based asp.net application the creates a thread to do some
background printing. It works fine but when the application is deployed on a
web server, the following error occurs in the thread when it accesses SQL:

Login failed for user ''. The user is not associated with a trusted SQL
Server connection.

Note the blank user. It seems that the new thread does not have the
credentials but looking at "Thread.CurrentPrincipal", there is a valid user
(me).

Is there something I am missing? Does the application need some assembly
permissions? I wonder if there are any settings under IIS? Is there any way
of telling why SQL cannot access the thread credentials?

Brian
Feb 5 '07 #1
5 5726
hi brian,
can you try it without using any threading code? also, verify that the code
is using a valid connection string. is it set to use integrated/windows
account logon? you've probably already tested that but no harm to check the
obvious things first.

tim

"Brian" <br**********@hotmail.comwrote in message
news:uL*************@TK2MSFTNGP05.phx.gbl...
>I have an file based asp.net application the creates a thread to do some
background printing. It works fine but when the application is deployed on
a web server, the following error occurs in the thread when it accesses
SQL:

Login failed for user ''. The user is not associated with a trusted SQL
Server connection.

Note the blank user. It seems that the new thread does not have the
credentials but looking at "Thread.CurrentPrincipal", there is a valid
user (me).

Is there something I am missing? Does the application need some assembly
permissions? I wonder if there are any settings under IIS? Is there any
way of telling why SQL cannot access the thread credentials?

Brian
Feb 5 '07 #2
when you create a thread, its identity is the process identity, not the
starting threads identity, so it will not match the pool account or
impersonation account. the the case of asp.net, its the id of the worker
process usually a network service account.

you need to pass the desired identity to the new thread and have the new
thread impersonate it.

-- bruce (sqlwork.com)

Brian wrote:
I have an file based asp.net application the creates a thread to do some
background printing. It works fine but when the application is deployed on a
web server, the following error occurs in the thread when it accesses SQL:

Login failed for user ''. The user is not associated with a trusted SQL
Server connection.

Note the blank user. It seems that the new thread does not have the
credentials but looking at "Thread.CurrentPrincipal", there is a valid user
(me).

Is there something I am missing? Does the application need some assembly
permissions? I wonder if there are any settings under IIS? Is there any way
of telling why SQL cannot access the thread credentials?

Brian

Feb 5 '07 #3
Hi Tim,

Yes it works fine without the threading code so the connection string is
valid which uses integrated/windows security account.

Brian

"Tim Mackey" <ti********@community.nospamwrote in message
news:F9**********************************@microsof t.com...
hi brian,
can you try it without using any threading code? also, verify that the
code is using a valid connection string. is it set to use
integrated/windows account logon? you've probably already tested that but
no harm to check the obvious things first.

tim

"Brian" <br**********@hotmail.comwrote in message
news:uL*************@TK2MSFTNGP05.phx.gbl...
>>I have an file based asp.net application the creates a thread to do some
background printing. It works fine but when the application is deployed on
a web server, the following error occurs in the thread when it accesses
SQL:

Login failed for user ''. The user is not associated with a trusted
SQL Server connection.

Note the blank user. It seems that the new thread does not have the
credentials but looking at "Thread.CurrentPrincipal", there is a valid
user (me).

Is there something I am missing? Does the application need some assembly
permissions? I wonder if there are any settings under IIS? Is there any
way of telling why SQL cannot access the thread credentials?

Brian

Feb 5 '07 #4
Hi Bruce,

Thanks for your comment - it sounds like you are right on the mark!
I tried adding the following line of code to the new thread. Note that
"this.Context.User" seems to return the correct security principle - the
impersonation account. It is also identical to Thread.CurrentPrincipal
before the statement. Is there something I have missed setting the thread
identity to impersonate the asp.net account?

Thread.CurrentPrincipal = this.Context.User;

I also tried adding the following statement because the app.domain principal
policy in the new thread (only under asp.net) defaulted to
"unauthenticated".

Thread.GetDomain().SetPrincipalPolicy(System.Secur ity.Principal.PrincipalPolicy.WindowsPrincipal);

This too didn't make any difference - the error was the same when the code
is run in a thread under asp.net (otherwise it works fine).

I note that "this.Context.Request.LogonUserIdentity" normally returns the
same as "this.Context.User.WindowsIdentity", except when running under the
thread account in which case it returns, "Invalid token for impersonation -
it cannot be duplicated." Is this the problem? Is there any way around this?

Thanks very much for your help in this. By the way do you know if there any
documentation on all this? Is there any other way of setting the thread
identity?

Brian

"bruce barker" <no****@nospam.comwrote in message
news:u9**************@TK2MSFTNGP02.phx.gbl...
when you create a thread, its identity is the process identity, not the
starting threads identity, so it will not match the pool account or
impersonation account. the the case of asp.net, its the id of the worker
process usually a network service account.

you need to pass the desired identity to the new thread and have the new
thread impersonate it.

-- bruce (sqlwork.com)

Brian wrote:
>I have an file based asp.net application the creates a thread to do some
background printing. It works fine but when the application is deployed
on a web server, the following error occurs in the thread when it
accesses SQL:

Login failed for user ''. The user is not associated with a trusted
SQL Server connection.

Note the blank user. It seems that the new thread does not have the
credentials but looking at "Thread.CurrentPrincipal", there is a valid
user (me).

Is there something I am missing? Does the application need some assembly
permissions? I wonder if there are any settings under IIS? Is there any
way of telling why SQL cannot access the thread credentials?

Brian

Feb 6 '07 #5
Hi Bruce,

I found another post under microsoft.public.dotnet.framework.aspnet.security
called "Exception when use asp.net with .net remoting". This suggested
looking at:

System.Security.Principal.WindowsIdentity.GetCurre nt();

This seems to be empty in the child thread so I added the following code to
the thread (either of these lines work):
((WindowsIdentity)this.Context.User.Identity).Impe rsonate();
((WindowsIdentity)Thread.CurrentPrincipal.Identity ).Impersonate();

This fixes the problem when running on Windows XP but on windows 2003 it
returns printing (system.drawing error) which I'll have to look into.

Thanks again,
Brian

"Brian" <br**********@hotmail.comwrote in message
news:uP**************@TK2MSFTNGP06.phx.gbl...
Hi Bruce,

Thanks for your comment - it sounds like you are right on the mark!
I tried adding the following line of code to the new thread. Note that
"this.Context.User" seems to return the correct security principle - the
impersonation account. It is also identical to Thread.CurrentPrincipal
before the statement. Is there something I have missed setting the thread
identity to impersonate the asp.net account?

Thread.CurrentPrincipal = this.Context.User;

I also tried adding the following statement because the app.domain
principal policy in the new thread (only under asp.net) defaulted to
"unauthenticated".

Thread.GetDomain().SetPrincipalPolicy(System.Secur ity.Principal.PrincipalPolicy.WindowsPrincipal);

This too didn't make any difference - the error was the same when the code
is run in a thread under asp.net (otherwise it works fine).

I note that "this.Context.Request.LogonUserIdentity" normally returns the
same as "this.Context.User.WindowsIdentity", except when running under the
thread account in which case it returns, "Invalid token for
impersonation - it cannot be duplicated." Is this the problem? Is there
any way around this?

Thanks very much for your help in this. By the way do you know if there
any documentation on all this? Is there any other way of setting the
thread identity?

Brian

"bruce barker" <no****@nospam.comwrote in message
news:u9**************@TK2MSFTNGP02.phx.gbl...
>when you create a thread, its identity is the process identity, not the
starting threads identity, so it will not match the pool account or
impersonation account. the the case of asp.net, its the id of the worker
process usually a network service account.

you need to pass the desired identity to the new thread and have the new
thread impersonate it.

-- bruce (sqlwork.com)

Brian wrote:
>>I have an file based asp.net application the creates a thread to do some
background printing. It works fine but when the application is deployed
on a web server, the following error occurs in the thread when it
accesses SQL:

Login failed for user ''. The user is not associated with a trusted
SQL Server connection.

Note the blank user. It seems that the new thread does not have the
credentials but looking at "Thread.CurrentPrincipal", there is a valid
user (me).

Is there something I am missing? Does the application need some assembly
permissions? I wonder if there are any settings under IIS? Is there any
way of telling why SQL cannot access the thread credentials?

Brian


Feb 6 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Matthew Groch | last post by:
Hi all, I've got a server that handles a relatively high number of concurrent transactions (on the magnitude of 1000's per second). Client applications establish socket connections with the...
2
by: Sgt. Sausage | last post by:
New to multi-threading (less than 24 hours at it <grin>) Anyway, it's all making sense, and working fairly well thus far, but I'm having a minor issue I'm not sure how to get around. I've got...
19
by: Dales | last post by:
I have a custom control that builds what we refer to as "Formlets" around some content in a page. These are basically content "wrapper" sections that are tables that have a colored header and...
4
by: Ben Kim | last post by:
Hello all, Does anyone have an example on how to implement the new SerialPort Class in VB.NET? I have been able to create the class, send (.WriteLine) to the port and Read from the port but...
5
by: taylorjonl | last post by:
I am completely baffled. I am writting a daemon application for my work to save me some time. The application works fine at my home but won't work right here at work. Basically I have a...
3
by: Ryan Pedersen | last post by:
I have a small program that executes a single very long running background thread today. The scope of all variables in the method that is running in this thread today are all local to the...
5
by: Newbie | last post by:
Hi all, Just want to comment on this thread. Seems like every discussion about this matter (setting up DB provider for membership) and all the samples/references given by some MVPs always...
176
by: nw | last post by:
Hi, I previously asked for suggestions on teaching testing in C++. Based on some of the replies I received I decided that best way to proceed would be to teach the students how they might write...
3
by: writser | last post by:
hey all, For my study I'm writing a simple threaded webcrawler and I am trying to do this in python. But somehow, using threads causes IDLE to crash on Windows XP (with the latest python...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.