No Trusted SQL Server Connection

J

Jonathan Wood

I'm a programmer but not a database administrator and really don't want to
be either.

After a fair amount of reading and many problems related to SQL and related
stuff, I finally figured out how to create a database in Visual Studio and
enter some data into it. Now, I'm trying to make a Web site application
populate an HTML table with that data. (Running locally.)

Now, when I run the code, I get the error "Login failed for user ''. The
user is not associated with a trusted SQL Server connection."

It appears to be related to my SQL connection string, which is currently
"Data Source=localhost\\SQLEXPRESS;Initial Catalog=DataTest;"

It seems like that should work. Can anyone help me figure out the problem?

Thanks.
 
D

David Browne

Jonathan Wood said:
I'm a programmer but not a database administrator and really don't want to
be either.

After a fair amount of reading and many problems related to SQL and
related
stuff, I finally figured out how to create a database in Visual Studio and
enter some data into it. Now, I'm trying to make a Web site application
populate an HTML table with that data. (Running locally.)

Now, when I run the code, I get the error "Login failed for user ''. The
user is not associated with a trusted SQL Server connection."

It appears to be related to my SQL connection string, which is currently
"Data Source=localhost\\SQLEXPRESS;Initial Catalog=DataTest;"

It seems like that should work. Can anyone help me figure out the problem?

This error means that the identity running the code has no permissions to
connect to SQL Server. The user identity running the code needs to have a
SQL Server Login or be a member of a group that has a SQL Server Login.

David
 
M

Miha Markic [MVP C#]

Hi Johanthan,

Take note that an asp.net application runs under asp.net credentials on
windowsxp and network service on w2k3. These are default settings you can
modify of course.
 
W

William \(Bill\) Vaughn

My blog has several entries on connecting that I hope you can leverage to
get connected. Unfortunately, the exception messages returned by ADO.NET are
so generic that it's really tough to determine the real cause of connection
issues.

First, take a look at your ConnectionString. To access the SQLEXPRESS
instance on your local system you need to address it correctly. It's not
based on or accessed through IIS so "localhost" won't help. You can use this
notation to access it:
Data Source=.\SQLEXPRESS; ...

Next, you always have to tell ADO.NET who you are--so SQL Server can see
what gives you the right to access this instance and the database you've
chosen. Generally, you'll need to include "Integrated security=SSPI" to tell
ADO.NET to use your Windows login credentials. This also assumes that you're
a member of the administrators group on the local system (hosting SQL
Server). If you aren't you'll have to use SQL Server Management Studio to
add your Windows credentials to the list of recognized logins and grant that
login rights to the database(s) you wish to access.

hth
--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
INETA Speaker
www.betav.com/blog/billva
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
 

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

Top