Connect to SQL Server

B

Barry

Hi

When trying to connect to SQL Server using the code below i get this message
at myConnection.Open() line

Login failed for user 'JACKSON-QS7MHO6H\ASPNET'

from where does it add \ASPNET
how do i log on

string mySelectQuery = "SELECT * FROM authors";
string myConnectString = "Persist Security Info=False;Integrated
Security=SSPI;database=pubs;server=JACKSON-QS7MHO6H;";
SqlCommand myCommand = new SqlCommand(mySelectQuery);
myCommand.Connection = new SqlConnection(myConnectString);

SqlConnection myConnection = new SqlConnection(myConnectString);
myCommand.CommandTimeout = 15;
myCommand.CommandType = CommandType.Text;
myConnection.Open();



Barry
 
J

Juan T. Llibre

Hi, Barry.

The issue you're seeing is that your database server doesn't
have a user named "JACKSON-QS7MHO6H\ASPNET"
with permissions to access the pubs database.

Since you're not specifying a username in your connection string,
the ASP.NET user is the one which attempts to login...and fails.

Add a user named "JACKSON-QS7MHO6H\ASPNET"
( that's "YourMachineName\ASPNET" ) to either SQL Server
or MSDE ( whichever you're using ) and give it permissions to
access the pubs database.
 
P

Patrick Olurotimi Ige

Barry you need ASPNET account to log into SQL SERVER(thats the ASPNET
WORK PROCESS ASP.NET uses).
Add ASPNET acct to your SQL server.
Hope that helps
Patrick
 
R

Riki

Barry said:
Hi

When trying to connect to SQL Server using the code below i get this
message at myConnection.Open() line

Login failed for user 'JACKSON-QS7MHO6H\ASPNET'

from where does it add \ASPNET
how do i log on

string mySelectQuery = "SELECT * FROM authors";
string myConnectString = "Persist Security Info=False;Integrated
Security=SSPI;database=pubs;server=JACKSON-QS7MHO6H;";
SqlCommand myCommand = new SqlCommand(mySelectQuery);
myCommand.Connection = new SqlConnection(myConnectString);

SqlConnection myConnection = new SqlConnection(myConnectString);
myCommand.CommandTimeout = 15;
myCommand.CommandType = CommandType.Text;
myConnection.Open();

Apart from allowing access to the ASPNET account (see
Juan's and Patrick's reply), you may also consider using
authentication and impersonation. This will make your
application run under the account that's logged on, and
if that account has access to your database, it will work.

Search Google for "ASP.NET impersonation".
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top