public partial class yanzheng : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string username = Request.Form["username"].ToString();
string userpassword = Request.Form.Get("userpassword").ToString(); SqlConnection con = new SqlConnection("server=.;database=text;uid=sa;pwd=fengqq6604;");
con.Open();
SqlCommand cmd = new SqlCommand("select count(*) from text where username ='" + username + "' and userpassword='" + userpassword + "'", con);
int count = Convert.ToInt32(cmd.ExecuteScalar());
if (count > 0)
{
Response.Redirect("main.aspx");
}
else
{
Response.Redirect("loginFail.htm");
}
}
}
代码如上
用的VS2005 数据库是用SA登陆的 密码什么都确定 执行到con.Open();出现异常
请问问题出在哪里 具体该如何解决?
{
protected void Page_Load(object sender, EventArgs e)
{
string username = Request.Form["username"].ToString();
string userpassword = Request.Form.Get("userpassword").ToString(); SqlConnection con = new SqlConnection("server=.;database=text;uid=sa;pwd=fengqq6604;");
con.Open();
SqlCommand cmd = new SqlCommand("select count(*) from text where username ='" + username + "' and userpassword='" + userpassword + "'", con);
int count = Convert.ToInt32(cmd.ExecuteScalar());
if (count > 0)
{
Response.Redirect("main.aspx");
}
else
{
Response.Redirect("loginFail.htm");
}
}
}
代码如上
用的VS2005 数据库是用SA登陆的 密码什么都确定 执行到con.Open();出现异常
请问问题出在哪里 具体该如何解决?
是数据库出问题了 因为没出过类似的问题具体我也不知道
代码没有问题!应该是你连接数据库服务器的时候出错了!
或权限的问题!
试试。