473,471 Members | 2,040 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Unable to get SQLConnection to Open() in BackgroundWorker

Hello,

In my ASP.Net app I'm launching a BackgroundWorker thread in my Page_Load
function. In that thread I'm attempting to connect to a SQL server using
this connection string "Initial Catalog=MyDB;Data Source=MyServer;Integrated
Security=True;".

When I use the same connection string in my main thread of execution it
works fine. However when I use that connection string in the newly created
thread I get this exception: "Login failed for user ''. The user is not
associated with a trusted SQL Server connection."

The '' (empty quotes) make me think I need to tell the new thread which user
credentials to use. Is that correct? If so, how do I do it? If not, what
do I need to do?

Thanks!
Jan 25 '07 #1
9 4980
"Initial Catalog=MyDB;Data Source=MyServer;uid=username;pwd=password;"

"TOM_Pasadena" <TO**********@discussions.microsoft.comwrote in message
news:45**********************************@microsof t.com...
Hello,

In my ASP.Net app I'm launching a BackgroundWorker thread in my Page_Load
function. In that thread I'm attempting to connect to a SQL server using
this connection string "Initial Catalog=MyDB;Data
Source=MyServer;Integrated
Security=True;".

When I use the same connection string in my main thread of execution it
works fine. However when I use that connection string in the newly
created
thread I get this exception: "Login failed for user ''. The user is not
associated with a trusted SQL Server connection."

The '' (empty quotes) make me think I need to tell the new thread which
user
credentials to use. Is that correct? If so, how do I do it? If not,
what
do I need to do?

Thanks!

Jan 25 '07 #2
Aidy,

Thanks for the reply. I need to use Windows Authentication. Your
connection string assumes SQL Authentication.

Any idea why my thread would not know my credentials?

"Aidy" wrote:
"Initial Catalog=MyDB;Data Source=MyServer;uid=username;pwd=password;"

"TOM_Pasadena" <TO**********@discussions.microsoft.comwrote in message
news:45**********************************@microsof t.com...
Hello,

In my ASP.Net app I'm launching a BackgroundWorker thread in my Page_Load
function. In that thread I'm attempting to connect to a SQL server using
this connection string "Initial Catalog=MyDB;Data
Source=MyServer;Integrated
Security=True;".

When I use the same connection string in my main thread of execution it
works fine. However when I use that connection string in the newly
created
thread I get this exception: "Login failed for user ''. The user is not
associated with a trusted SQL Server connection."

The '' (empty quotes) make me think I need to tell the new thread which
user
credentials to use. Is that correct? If so, how do I do it? If not,
what
do I need to do?

Thanks!


Jan 25 '07 #3
See valid connection string variations at :

http://www.connectionstrings.com/?carrier=sqlserver

It looks like you want to use SqlConnection ( .NET ).
Check the SqlConnection (.NET) section and pick one.


Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
"TOM_Pasadena" <TO*********@discussions.microsoft.comwrote in message
news:8A**********************************@microsof t.com...
Aidy,

Thanks for the reply. I need to use Windows Authentication. Your
connection string assumes SQL Authentication.

Any idea why my thread would not know my credentials?

"Aidy" wrote:
>"Initial Catalog=MyDB;Data Source=MyServer;uid=username;pwd=password;"

"TOM_Pasadena" <TO**********@discussions.microsoft.comwrote in message
news:45**********************************@microso ft.com...
Hello,

In my ASP.Net app I'm launching a BackgroundWorker thread in my Page_Load
function. In that thread I'm attempting to connect to a SQL server using
this connection string "Initial Catalog=MyDB;Data
Source=MyServer;Integrated
Security=True;".

When I use the same connection string in my main thread of execution it
works fine. However when I use that connection string in the newly
created
thread I get this exception: "Login failed for user ''. The user is not
associated with a trusted SQL Server connection."

The '' (empty quotes) make me think I need to tell the new thread which
user
credentials to use. Is that correct? If so, how do I do it? If not,
what
do I need to do?

Thanks!



Jan 25 '07 #4
Thanks for your response. However, that article doesn't address my issue. I
need to understand why my thread doesn't have the same credentials as my
process.

"Juan T. Llibre" wrote:
See valid connection string variations at :

http://www.connectionstrings.com/?carrier=sqlserver

It looks like you want to use SqlConnection ( .NET ).
Check the SqlConnection (.NET) section and pick one.


Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
"TOM_Pasadena" <TO*********@discussions.microsoft.comwrote in message
news:8A**********************************@microsof t.com...
Aidy,

Thanks for the reply. I need to use Windows Authentication. Your
connection string assumes SQL Authentication.

Any idea why my thread would not know my credentials?

"Aidy" wrote:
"Initial Catalog=MyDB;Data Source=MyServer;uid=username;pwd=password;"

"TOM_Pasadena" <TO**********@discussions.microsoft.comwrote in message
news:45**********************************@microsof t.com...
Hello,

In my ASP.Net app I'm launching a BackgroundWorker thread in my Page_Load
function. In that thread I'm attempting to connect to a SQL server using
this connection string "Initial Catalog=MyDB;Data
Source=MyServer;Integrated
Security=True;".

When I use the same connection string in my main thread of execution it
works fine. However when I use that connection string in the newly
created
thread I get this exception: "Login failed for user ''. The user is not
associated with a trusted SQL Server connection."

The '' (empty quotes) make me think I need to tell the new thread which
user
credentials to use. Is that correct? If so, how do I do it? If not,
what
do I need to do?

Thanks!


Jan 26 '07 #5
re:
I need to understand why my thread doesn't have the same credentials as my process.
Simple...

You are connecting using a Trusted Connection, but are not including
"Integrated Security=SSPI" nor "Trusted_Connection=Yes" in your connection string

The connection string used with Windows authentication must include either the
Trusted_Connection=Yes attribute, or the equivalent attribute Integrated Security=SSPI,
as shown in "How To: Connect to SQL Server Using Windows Authentication in ASP.NET 2.0"

http://msdn2.microsoft.com/en-us/library/ms998292.aspx


Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
"TOM_Pasadena" <TO*********@discussions.microsoft.comwrote in message
news:03**********************************@microsof t.com...
Thanks for your response. However, that article doesn't address my issue. I
need to understand why my thread doesn't have the same credentials as my
process.
"Juan T. Llibre" wrote:
>See valid connection string variations at :

http://www.connectionstrings.com/?carrier=sqlserver

It looks like you want to use SqlConnection ( .NET ).
Check the SqlConnection (.NET) section and pick one.
Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
"TOM_Pasadena" <TO*********@discussions.microsoft.comwrote in message
news:8A**********************************@microso ft.com...
Aidy,

Thanks for the reply. I need to use Windows Authentication. Your
connection string assumes SQL Authentication.

Any idea why my thread would not know my credentials?

"Aidy" wrote:

"Initial Catalog=MyDB;Data Source=MyServer;uid=username;pwd=password;"

"TOM_Pasadena" <TO**********@discussions.microsoft.comwrote in message
news:45**********************************@microso ft.com...
Hello,

In my ASP.Net app I'm launching a BackgroundWorker thread in my Page_Load
function. In that thread I'm attempting to connect to a SQL server using
this connection string "Initial Catalog=MyDB;Data
Source=MyServer;Integrated
Security=True;".

When I use the same connection string in my main thread of execution it
works fine. However when I use that connection string in the newly
created
thread I get this exception: "Login failed for user ''. The user is not
associated with a trusted SQL Server connection."

The '' (empty quotes) make me think I need to tell the new thread which
user
credentials to use. Is that correct? If so, how do I do it? If not,
what
do I need to do?

Thanks!



Jan 26 '07 #6
That doesn't work either. Keep in mind that the connection string in my
original posting works fine while I'm in the primary thread of execution.
It's only in the new thread that it fails. When I change to "Integrated
Security=SSPI" again it works in my primary thread but not the
backgroundWorker thread.

"Juan T. Llibre" wrote:
re:
I need to understand why my thread doesn't have the same credentials as my process.

Simple...

You are connecting using a Trusted Connection, but are not including
"Integrated Security=SSPI" nor "Trusted_Connection=Yes" in your connection string

The connection string used with Windows authentication must include either the
Trusted_Connection=Yes attribute, or the equivalent attribute Integrated Security=SSPI,
as shown in "How To: Connect to SQL Server Using Windows Authentication in ASP.NET 2.0"

http://msdn2.microsoft.com/en-us/library/ms998292.aspx


Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
"TOM_Pasadena" <TO*********@discussions.microsoft.comwrote in message
news:03**********************************@microsof t.com...
Thanks for your response. However, that article doesn't address my issue. I
need to understand why my thread doesn't have the same credentials as my
process.
"Juan T. Llibre" wrote:
See valid connection string variations at :

http://www.connectionstrings.com/?carrier=sqlserver

It looks like you want to use SqlConnection ( .NET ).
Check the SqlConnection (.NET) section and pick one.
Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
"TOM_Pasadena" <TO*********@discussions.microsoft.comwrote in message
news:8A**********************************@microsof t.com...
Aidy,

Thanks for the reply. I need to use Windows Authentication. Your
connection string assumes SQL Authentication.

Any idea why my thread would not know my credentials?

"Aidy" wrote:

"Initial Catalog=MyDB;Data Source=MyServer;uid=username;pwd=password;"

"TOM_Pasadena" <TO**********@discussions.microsoft.comwrote in message
news:45**********************************@microsof t.com...
Hello,

In my ASP.Net app I'm launching a BackgroundWorker thread in my Page_Load
function. In that thread I'm attempting to connect to a SQL server using
this connection string "Initial Catalog=MyDB;Data
Source=MyServer;Integrated
Security=True;".

When I use the same connection string in my main thread of execution it
works fine. However when I use that connection string in the newly
created
thread I get this exception: "Login failed for user ''. The user is not
associated with a trusted SQL Server connection."

The '' (empty quotes) make me think I need to tell the new thread which
user
credentials to use. Is that correct? If so, how do I do it? If not,
what
do I need to do?

Thanks!



Jan 26 '07 #7
I haven't used .net 2.0 but I image the backgroundworker thread might be
running in its own process somewhere, or a special process space that is
outside of IIS, so it is not using the same credentials as your asp.net code
is using.

As I said, that's just a guess. Look at the docs to see if you can specify
credentials to the background thread, or find out the credentials of the
thread it is using and add those as a trusted SQL member. Failing that,
create a SQL user just for that process and pass the uid and pwd with the
connect string.

"TOM_Pasadena" <TO*********@discussions.microsoft.comwrote in message
news:3C**********************************@microsof t.com...
That doesn't work either. Keep in mind that the connection string in my
original posting works fine while I'm in the primary thread of execution.
It's only in the new thread that it fails. When I change to "Integrated
Security=SSPI" again it works in my primary thread but not the
backgroundWorker thread.

"Juan T. Llibre" wrote:
>re:
I need to understand why my thread doesn't have the same credentials as
my process.

Simple...

You are connecting using a Trusted Connection, but are not including
"Integrated Security=SSPI" nor "Trusted_Connection=Yes" in your
connection string

The connection string used with Windows authentication must include
either the
Trusted_Connection=Yes attribute, or the equivalent attribute Integrated
Security=SSPI,
as shown in "How To: Connect to SQL Server Using Windows Authentication
in ASP.NET 2.0"

http://msdn2.microsoft.com/en-us/library/ms998292.aspx


Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
"TOM_Pasadena" <TO*********@discussions.microsoft.comwrote in message
news:03**********************************@microso ft.com...
Thanks for your response. However, that article doesn't address my
issue. I
need to understand why my thread doesn't have the same credentials as
my
process.
"Juan T. Llibre" wrote:

See valid connection string variations at :

http://www.connectionstrings.com/?carrier=sqlserver

It looks like you want to use SqlConnection ( .NET ).
Check the SqlConnection (.NET) section and pick one.
Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
"TOM_Pasadena" <TO*********@discussions.microsoft.comwrote in
message
news:8A**********************************@microso ft.com...
Aidy,

Thanks for the reply. I need to use Windows Authentication. Your
connection string assumes SQL Authentication.

Any idea why my thread would not know my credentials?

"Aidy" wrote:

"Initial Catalog=MyDB;Data
Source=MyServer;uid=username;pwd=password;"

"TOM_Pasadena" <TO**********@discussions.microsoft.comwrote in
message
news:45**********************************@microso ft.com...
Hello,

In my ASP.Net app I'm launching a BackgroundWorker thread in my
Page_Load
function. In that thread I'm attempting to connect to a SQL
server using
this connection string "Initial Catalog=MyDB;Data
Source=MyServer;Integrated
Security=True;".

When I use the same connection string in my main thread of
execution it
works fine. However when I use that connection string in the
newly
created
thread I get this exception: "Login failed for user ''. The user
is not
associated with a trusted SQL Server connection."

The '' (empty quotes) make me think I need to tell the new thread
which
user
credentials to use. Is that correct? If so, how do I do it? If
not,
what
do I need to do?

Thanks!




Jan 26 '07 #8
Hi, Tom.

Have you tried posting your question in the SQL Server Security forum ?

http://forums.microsoft.com/MSDN/Sho...ID=92&SiteID=1

Microsoft SQL Server staffers man that forum
and may have the specialized knowledge you need.

Here's a list of 70 threads which mention BackgroundWorker in the SQL Forums:
http://forums.microsoft.com/MSDN/Sea...localechoice=9

You might want to give them a glance and see
if others have posted something which might help you.

Other than that, opening a Support ticket may be your last resort.


Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
"TOM_Pasadena" <TO*********@discussions.microsoft.comwrote in message
news:3C**********************************@microsof t.com...
That doesn't work either. Keep in mind that the connection string in my
original posting works fine while I'm in the primary thread of execution.
It's only in the new thread that it fails. When I change to "Integrated
Security=SSPI" again it works in my primary thread but not the
backgroundWorker thread.

"Juan T. Llibre" wrote:
>re:
I need to understand why my thread doesn't have the same credentials as my process.

Simple...

You are connecting using a Trusted Connection, but are not including
"Integrated Security=SSPI" nor "Trusted_Connection=Yes" in your connection string

The connection string used with Windows authentication must include either the
Trusted_Connection=Yes attribute, or the equivalent attribute Integrated Security=SSPI,
as shown in "How To: Connect to SQL Server Using Windows Authentication in ASP.NET 2.0"

http://msdn2.microsoft.com/en-us/library/ms998292.aspx


Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
"TOM_Pasadena" <TO*********@discussions.microsoft.comwrote in message
news:03**********************************@microso ft.com...
Thanks for your response. However, that article doesn't address my issue. I
need to understand why my thread doesn't have the same credentials as my
process.
"Juan T. Llibre" wrote:

See valid connection string variations at :

http://www.connectionstrings.com/?carrier=sqlserver

It looks like you want to use SqlConnection ( .NET ).
Check the SqlConnection (.NET) section and pick one.
Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
"TOM_Pasadena" <TO*********@discussions.microsoft.comwrote in message
news:8A**********************************@microso ft.com...
Aidy,

Thanks for the reply. I need to use Windows Authentication. Your
connection string assumes SQL Authentication.

Any idea why my thread would not know my credentials?

"Aidy" wrote:

"Initial Catalog=MyDB;Data Source=MyServer;uid=username;pwd=password;"

"TOM_Pasadena" <TO**********@discussions.microsoft.comwrote in message
news:45**********************************@microso ft.com...
Hello,

In my ASP.Net app I'm launching a BackgroundWorker thread in my Page_Load
function. In that thread I'm attempting to connect to a SQL server using
this connection string "Initial Catalog=MyDB;Data
Source=MyServer;Integrated
Security=True;".

When I use the same connection string in my main thread of execution it
works fine. However when I use that connection string in the newly
created
thread I get this exception: "Login failed for user ''. The user is not
associated with a trusted SQL Server connection."

The '' (empty quotes) make me think I need to tell the new thread which
user
credentials to use. Is that correct? If so, how do I do it? If not,
what
do I need to do?

Thanks!




Jan 26 '07 #9
"TOM_Pasadena" wrote:
That doesn't work either. Keep in mind that the connection string in my
original posting works fine while I'm in the primary thread of execution.
It's only in the new thread that it fails. When I change to "Integrated
Security=SSPI" again it works in my primary thread but not the
backgroundWorker thread.
Tom-

No idea if this would work for you, but it's a path I just mowed out for
myself:

I was not able to fork the BackgroundWorker from my code. I'm in a VB
module in a 2.0 web app, but the code is not part of an aspx page. I got an
exception on the line RunWorkerAsync(): "Asynch not allowed here, page must
have async attribute set to true." While I was surfing for a way to set the
"page attribute" in a non-page module, I came across this article:

http://www.beansoftware.com/ASP.NET-...n-Pattern.aspx

from which, I created my own version of a background worker thread (below).
Not sure how safe/sound my approach is, and would love any feedback on it,
but I am accessing multiple DB's from the low priority thread.

Public Class Test
Public Delegate Sub LongTimeTask_Delegate(ByVal s As String)

Public Shared Sub makeBGW()
'Dim w As BackgroundWorker = New BackgroundWorker()
'AddHandler w.DoWork, New DoWorkEventHandler(AddressOf OnWork)
'w.RunWorkerAsync() 'chokes here
Dim d As LongTimeTask_Delegate = New LongTimeTask_Delegate(AddressOf
LongTimeTask)
Dim r As IAsyncResult = d.BeginInvoke("abcdef", Nothing, Nothing)
End Sub

Public Shared Sub LongTimeTask(ByVal s As String)
Thread.CurrentThread.Priority = ThreadPriority.Lowest
'doing background junk right here, including access to multiple DB's
End Sub

etc..

I do conflict with this guy's rule #19 (changing a thread's priority), but
wasn't sure what else to do here.
http://www.feedshow.com/show_items-f...76e00d301b57da

Hope it helps. Sorry so long.
Jan 27 '07 #10

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

Similar topics

2
by: arran.pearce | last post by:
Hi, I am using .NET 2 (beta2) and are having problems with using a SqlConnection. I have created a test application that opens a sql connections, gets some basic data and then closes the...
4
by: arran.pearce | last post by:
Hi, I am using .NET 2 (beta2) and are having problems with using a SqlConnection. I have created a test application that opens a sql connections, gets some basic data and then closes the...
3
by: Stephen | last post by:
I'm experiencing a strange problem that has me baffled. I created a webservice with a webmethod that connects to a remote MS SQL Server. It works fine when connecting to one server (running SQL...
4
by: Nevyn Twyll | last post by:
I've been working on an asp.net application and everything's been great. But suddenly, whether I'm tyring to use a database on my own machine, or on my server, I'm getting a timeout when trying to...
6
by: Brad | last post by:
I have a win2003 server workstation with multiple webs, each web has it's own ip address. In VS2005, if I select to open an existing web site, select Local IIS, the dialog correctly displays a...
7
by: Jed | last post by:
I am trying to open web project in VS 2003 using the File Share method. VS is running on XP Pro (Host) and I am accessing the root web of an XP Pro install on Virtual PC (Server) running on the...
0
by: bazzer | last post by:
hey, i am using visual basic.net 2003 and have an ASP.NET webform application thats accessing a microsoft access 2003 database. i kept getting the following error when i tried to run it: ERROR ...
0
by: bazzer | last post by:
hey, im trying to access a microsoft access database from an ASP.NET web application in visual basic 2003.NET. i get the following error when i try running it: Server Error in...
1
by: geetu | last post by:
hi to all.. pls help me its urgent.. i m unable to understand the exact answer .. tell me step to be carried to set libraries or directory path so that i can execute a simple program everytime i...
1
by: Hanu | last post by:
I am unable to load open a file using vlcwidget.py. Could not get it working. ANy experience to share? C:\workspace\python-HEAD\python>vlcwidget.py trn_anaglyph_adj.mpg libdvdnav: Using dvdnav...
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.