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();出现异常
请问问题出在哪里 具体该如何解决?

解决方案 »

  1.   

    哦对了 忘记说明  我用的是万恶的SQL2005 T0T
      

  2.   

    我用的是MS-sql没出现过这样的问题  只能说你这不是代码的问题 
    是数据库出问题了 因为没出过类似的问题具体我也不知道
      
      

  3.   

    我装的微软的SQL2005 ! 没有出现过这样的问题! 
    代码没有问题!应该是你连接数据库服务器的时候出错了!
    或权限的问题!
      

  4.   

    SqlConnection con = new SqlConnection("server=服务器;database=text;user id=sa;pwd=fengqq6604;"); 
    试试。