Connection string does not work from asp.net web application

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

If I run the following code on my development machine as a "Windows
Application", it works. If I run the following code on my development
machine as an "ASP.NET Web Application", I get the error "SQL Server does not
exist or access denied." when trying to open the connection. I would
appreciate any assistance in determining why.

Private Sub TestAdo()
Dim conn As New System.Data.SqlClient.SqlConnection
Dim cmd As New System.Data.SqlClient.SqlCommand
Dim dr As System.Data.SqlClient.SqlDataReader
conn.ConnectionString = "Data
Source=np:SQLSERVER1;uid=username;pwd=password;Initial
Catalog=STARMT;Connection Timeout=5;"
conn.Open()
cmd.Connection = conn
cmd.CommandText = "select * from customers"
dr = cmd.ExecuteReader()
Do While dr.Read
'
Loop
dr.Close()
conn.Close()
End Sub


Thanks in advance.

Clay
 
Hi,

It means that most likely you do not have permissions for ASPNET account to
access SQL Server database. Check if your ASPNET account exists in a list of
the users for login in a SQL Server database. You would also need to grant
permissions for ASPNET account to run specific SPs or access specific tables
 
No, he's passing in the username and password in the connection string.

What happens if you drop a DataAdapter on the form, and go through the
Wizard? You can then view the connection string created

Jeff
 
Do you want to say that passing user and password in a connection string is
not allowed?
 
You mentioned the ASPNET account, I mentioned that he's connecting via
Standard SQL auth, it appears.

Jeff
 
Jeff,

Thanks for the tip. The connection string created by the sqldataadapter
worked.

Turns out it has to do with trying to connect using named pipes from my
asp.net app. I did try using tcp with my original connection string and that
failed aswell, but this new connection string through tcp works fine. Thanks
again.

Here is new connection string i'm using that works:
"workstation id=DEVCOMP;packet size=4096;user
id=username;Password=password;data source=SQLSERVER1;persist security
info=False;initial catalog=STARMT"
 
Back
Top