我尝试创建一个登录页面。我收到以下错误。我在Google上搜索了解决方案,但他们都没有帮助我。
无法打开数据库" 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 =@UserName and Password=@Password", 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;Password=admin@123"/></connectionStrings>
无法找到我的错误。谢谢。
答案 0 :(得分:-1)
如果运行应用程序的用户帐户可以访问数据库,则应该具有“Integrated Security = true”。
我看到您通过提供特定的userId和密码来使用SQL身份验证。如果您确实需要SQL身份验证,请将Integrated Security标记为false。
让我知道这是否有效。