Hi,
I am new to .net. I'm developing a sample web application in ASP .net (using C#). I am trying to connect to the database & i keep getting this error. I'm trying to authenticate the username & password that the user enters with my backend table & print it on the page. But I keep getting -->
Login failed for user 'CRM\ASPNET'. Exception Details: System.Data.SqlClient.SqlException: Login failed for user 'CRM\ASPNET'.
My code is :
myConn = new SqlConnection("Initial Catalog=repository;Data Source=localhost;Integrated Security=SSPI;");
myCmd = myConn.CreateCommand();
myCmd.CommandText = "SELECT loginname, password FROM Employee where loginname = '"+TextBox1.Text +"' and password = '"+TextBox2.Text+"'";
myConn.Open();
myReader = myCmd.ExecuteReader();
while (myReader.Read())
{
results = results + myReader.GetString(0) + ", " + myReader.GetString(1) ;
}
Can anyone help me debug this problem. I cannot proceed further till i solve this...PLZ HELP!!!!
gopal krishna9 reputationPosted Jul 13, 2006, 2:38 AM EDT
here this is ur s ..
myConn = new SqlConnection("Initial Catalog=repository;Data Source=localhost;Integrated Security=SSPI;");
and this is mine...
myConn = new SqlConnection("server=yourservername;user id=sa;password=sqlserverpassword;database=urdatabasename(ex:pubs)");
servername ,
user id,
password,
and database name ...
above mentioned 4 types are enough for connecting to database...
example:
myConn = new SqlConnection("server=krishna;user id=sa;password=kriss;database=pubs");
and this connection u better to write in webconfig file...thats safe place for connectionstring..
if u have any doughts u just mail me...hope i may help u...
Dinesh TawarRank #4,458 · 342 reputationPosted Jul 14, 2006, 1:48 AM EDT
try this connection string
connectionstring = "server='nameofsqlserver'; database='name ofdatabase'; uid ='userid'; pwd ='password'"
Adam10 reputationPosted Jul 17, 2006, 7:32 AM EDT
When you specify Integrated Security=SSPI in your connection string your code will try to open a connection with the account that is running your ASP.NET application, whether it be an annonymous account or a windows account.
To allow this to happen you must add the account to the logins section of SQL server and grant the account access to your DB.
Dipen LamaRank #3,323 · 432 reputationPosted Jul 17, 2006, 8:57 PM EDT
Also it is better to keep the connection string in the web.config files and read from it. You dont have to rebuilt the application when you change your connection string in web.config. Find out how to store and read the connection string from web.config file, its a standard practice.
Muhammad Asif7 reputationPosted Jul 25, 2006, 4:42 AM EDT