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!!!!
Muhammad AsifPosted Jul 25, 2006, 8:42 AM
Dipen LamaPosted Jul 18, 2006, 12:57 AM
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.
AdamPosted Jul 17, 2006, 11:32 AM
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.
Dinesh TawarPosted Jul 14, 2006, 5:48 AM
try this connection string
connectionstring = "server='nameofsqlserver'; database='name ofdatabase'; uid ='userid'; pwd ='password'"
gopal krishnaPosted Jul 13, 2006, 6:38 AM
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...