2016-05-05 56 views
0

我尝试创建登录页面。我收到以下错误。我在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。

+0

您确定您传递的连接字符串密码正确吗? –

+0

是@RachitGupta – Kusum

+0

标题中的例外如何与此相关?请不要存储密码而不用散列它们。 –

回答

-1

如果运行应用程序的用户帐户有权访问数据库,则应该具有“Integrated Security = true”。

我看到您正在使用SQL身份验证,通过提供特定的userId和密码。如果您确实需要SQL身份验证,请将Integrated Security标记为false。

让我知道这是否工作。

+1

它已经在评论中回答什么是你的答案中特别的? – Mostafiz

+0

哎呀!没有检查...是一个新的生物......所以... –

相关问题