Click here to Skip to main content
15,949,741 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
how to solve this error


SqlCommand cmd = new SqlCommand("select Count(*) from systemlogin where Username='" + Textbox1.Text + "','" + Textbox2.Text + "'", con);

cmd.Parameters.AddWithValue("@Username", Textbox1.Text);
cmd.Parameters.AddWithValue("@Password", Textbox2.Text);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);

if (dt.Rows.Count>0)
{
Response.Redirect("design.aspx");
}
else
{
Response.Write("Invalid name");
}
Posted
Comments
[no name] 10-Jul-14 7:04am    
"Login failed for user 'sa'" is pretty self explanatory is it not?

1 solution

Good grief!
So very many bad things to do in one question...

First off, why the heck are you using user "sa"? That is the default system admin for the whole SQL instance, and it has complete control over all databases, not just yours. So from a security point of view it's a very, very poor idea to use it in your code - you should be using a user with just enough permissions to do his job - on that one database. The "sa" user should not even exist, or should have it's password changed immediately the installation is complete!

Which leads us into the second point: Do not concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Use Parametrized queries instead. Combine this with using "sa" access, and you risk evey database on the server...

And talking of risks...The third thing: Never store passwords in clear text - it is a major security risk. There is some information on how to do it here: Password Storage: How to do it.[^]

So...what's causing your problem? I suspect that it's because you have grabbed some code from the internet which looks like it might do something like what you want, and chucked it into your application without thinking about how it is supposed to work.

Don't.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900