Last post Aug 08, 2007 07:33 AM by Ganesh@Nilgris
Aug 07, 2007 08:43 PM|scanja|LINK
I am using visual studio 2003 and i am trying to connect to a SQL database for a web applicaiton I am building. In the server explorer, I am able to add my MS SQL 2000 database and view the tables in the database I want to use. I create a sqlDataAdapter
and access one of the tables using the wizard. I then create a dataset and bind it to a datgrid. I build the web application and there are no error. When I view the .aspx page, i get an error 'Login failed for user 'userid'. If I am able to view the database
in the server explorer, why am I getting a login error? Any help would be appreciated.
Visual studio 2003 web.config intellisense
Visual Studio 2003
Aug 08, 2007 03:18 AM|johram|LINK
SQL server allows two types of authentication: windows and SQL. By default, when you create a connection to an SQL server, it will pick windows authentication for you. So when you run the web on your local machine, it will run in the context of your user.
And the connection to SQL will also be done in the context of your user. Now, when you browse the web from a server running IIS, it will run with a local machine account. This account cannot access the SQL server over the network.
So basically, you have two options here. If you're on a local network and your users are well-known then it might be appropriate to let SQL use windows authentication, and you also make sure your web uses (integrated) windows authentication.
The other option is to switch to SQL authentication, which means that your web will connect to the SQL server with the same user every time. And this user is local to the SQL server only, no need for an AD account. A problem with this solution is that you
need to store the username and password somewhere in your web.config. But there are ways to encrypt the connection string info with help of aspnet_regiis.exe command line tool. See this article for more info on this: http://aspnet.4guysfromrolla.com/articles/021506-1.aspx
If this post was useful to you, please mark it as answer. Thank you!
Aug 08, 2007 05:30 AM|abhi.in.forum|LINK
Use the following:-
con.ConnectionString = "Server=Server_Name;database=database_name;User ID=user_Id;Password=user_pswd;Trusted_Connection=false"
Dim adpt As
datagrid1.datasource = ds
Aug 08, 2007 07:33 AM|Ganesh@Nilgris|LINK
use the following to connect sql database not windows authentication
con.connectionstring = "Server=server_name;uid=sa;pwd=password;database=northwind"
but before the connection to work . login to sql using sql query analyser and enter the user id and the password.
if u are able to login properly then the above connection should work properly
further in the sql properties in sql enterpreise manager should be changed to allow the sql access