我尝试创建登录页面。我收到以下错误。我在Google上搜索解决方案,但他们都没有帮助我。登录失败:SqlException被用户代码未处理
无法打开登录请求的数据库“WebApp”。登录失败。 用户'用户名'登录失败。
我的代码 -
protected void loginbtn(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["dbconnection"].ConnectionString);
con.Open();
SqlCommand cmd = new SqlCommand("select * from UserProfile where UserName [email protected] and [email protected]", con);
cmd.Parameters.AddWithValue("@UserName", txtUserName.Text);
cmd.Parameters.AddWithValue("@Password", txtPWD.Text);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
if (dt.Rows.Count > 0)
{
Response.Redirect("Default.aspx");
}
else
{
ClientScript.RegisterStartupScript(Page.GetType(), "validation", "<script language='javascript'>alert('Invalid Username and Password')</script>");
}
}
Web配置代码:
<connectionStrings>
<add name="dbconnection" connectionString="Data Source=GLN027\SQL2008R2EXPRESS;Integrated Security=true;Initial Catalog=WebApp; User ID=sa;[email protected]"/></connectionStrings>
无法找到我的mistake.Thanks。
您确定您传递的连接字符串密码正确吗? –
是@RachitGupta – Kusum
标题中的例外如何与此相关?请不要存储密码而不用散列它们。 –