我用Microsoft Visual Studio 2008编了一个登录界面,在调试时出现无法与数据库连接的错误,请求帮助一下
程序如下:SqlConnectionconn=newSqlConnection(@"DataSource=.\SQLEXPRESS;AttachDbFilename=D:...
程序如下:
SqlConnection conn = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=D:\WebKDGLXT\App_Data\KDDB.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True");
conn.Open();
SqlCommand cmd = new SqlCommand("select UserName,UserPwd from UserInfo where UserName='" + txtUsername.Text.Trim().ToLower() + "'and UserPwd='" + txtUserPwd.Text.Trim() + "'", conn);
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
Response.Redirect("Default.aspx");
}
else
{
Response.Write("<script>alert('用户名或密码错误!')</script>");
}
dr.Close();
conn.Close(); 展开
SqlConnection conn = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=D:\WebKDGLXT\App_Data\KDDB.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True");
conn.Open();
SqlCommand cmd = new SqlCommand("select UserName,UserPwd from UserInfo where UserName='" + txtUsername.Text.Trim().ToLower() + "'and UserPwd='" + txtUserPwd.Text.Trim() + "'", conn);
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
Response.Redirect("Default.aspx");
}
else
{
Response.Write("<script>alert('用户名或密码错误!')</script>");
}
dr.Close();
conn.Close(); 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询