System.InvalidOperationException: ConnectionString 属性尚未初始化。 在 System.Data.SqlClient.SqlConnection.PermissionDemand() 在 System.Data.SqlClient.SqlConnectionFactory.PermissionDemand(DbConnection outerConnection) 在 System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) 在 System.Data.SqlClient.SqlConnection.Open() 在 GradeMis.Login.userLogin() 位置 H:\GradeMis\Login.aspx.cs:行号 41 是什么意思啊?
高手快救救我啊!!

解决方案 »

  1.   

    登陆的时候出现的上面的问题。我的登录的代码是:#region
    private void userLogin()
            {
                
    string sql = string.Empty;
    string user = this.txtUsername.Text;
    string pwd = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(this.txtPassword.Text,"MD5");
                sql = string.Format("select username,password,[group] from admin where username='{0}' and password='{1}'",user,pwd);
    SqlDataReader dr;
    SqlCommand cmd = new SqlCommand(sql,conn);
    try
                {
                    SqlConnection Conn = new SqlConnection(Conn); 
                    conn.Open(); dr = cmd.ExecuteReader();
    if(dr.Read())
    {
    Session["username"] = dr["username"].ToString();
    Session["group"] = dr["group"].ToString();
    Response.Redirect("Main.aspx");
    }
    else
    {
    Response.Write("<script>alert('用户名或者密码错误,请重新输入!')</script>");
    }
    }
    catch(Exception ex)
    {
    Response.Write(ex);
    }
    finally
    {
    conn.Close();
    }
    }
    #endregion
    哪里有错吗?
      

  2.   

    SqlCommand cmd = new SqlCommand(sql,conn); 
    try 
                { 
                    SqlConnection Conn = new SqlConnection(Conn); 
                    conn.Open(); 
    写反了  没连接你就先执行了
      

  3.   

    sql = string.Format("select username,password,[group] from admin where username='{0}' and password='{1}'",user,pwd); SqlConnection Conn = new SqlConnection(Conn); 
       conn.Open(); 
    SqlDataReader dr; 
    SqlCommand cmd = new SqlCommand(sql,conn); 
    先打开,再执行
      

  4.   

    http://www.ideaext.com/read.php/293.htm
      

  5.   

    SqlConnection Conn = new SqlConnection(Conn); 
    这句有问题,SqlConnection的参数应该是连接数据库的字符串。
      

  6.   

    SqlConnection Conn = new SqlConnection("这里面是连接字符串");
    "Data Source='计算机名称、也可以使IP地址、如果是本机可以用'.'表示';Initial Catalog=数据库名称;Integrated Security=True"如果非windows登陆、 还需要账号和密码、 在上面的字符串后面加、'User ID=sa;pwd=123'
    希望能帮到你、
      

  7.   

    conn??????Conn??????????
    你的程序对这两个变量声明没有,有的话贴出来大家看看。给楼主一个网站如何编写连接字符串的网站很好www.connectionstrings.com
      

  8.   

    我们同学给我说这样改:可是还是有错误
     public class Login : System.Web.UI.Page
    {
    protected System.Web.UI.WebControls.Button Button1;
    protected System.Web.UI.WebControls.TextBox txtPassword;
    protected System.Web.UI.WebControls.TextBox txtUsername;
            private static readonly string connestr = ConfigurationManager.ConnectionStringS["GradeSysConnectionString"].ToString();
    private void Page_Load(object sender, System.EventArgs e)
    {
    // 在此处放置用户代码以初始化页面
     
    }
     #region 
    private void userLogin() 
            { 
                
    string sql = string.Empty; 
    string user = this.txtUsername.Text; 
    string pwd  =System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(this.txtPassword.Text,"MD5"); 
                sql = string.Format("select username,password,[group] from admin where username='{0}' and password='{1}'",user,pwd); 
    SqlConnection Conn = new SqlConnection(Connestr); 
    SqlDataReader dr; 
    SqlCommand cmd = new SqlCommand(sql,Conn); 
    try 
                { 
                    
                    Conn.Open(); dr = cmd.ExecuteReader(); 
    if(dr.Read()) 

    Session["username"] = dr["username"].ToString(); 
    Session["group"] = dr["group"].ToString(); 
    Response.Redirect("Main.aspx"); 

    else 

    Response.Write(" <script>alert('用户名或者密码错误,请重新输入!') </script>"); 


    catch(Exception ex) 

    Response.Write(ex); 

    finally 

    conn.Close(); 


    #endregion 
      

  9.   

    SqlConnection Conn = new SqlConnection(Connestr); 
    SqlDataReader dr; 
    SqlCommand cmd = new SqlCommand(sql,Conn); 
    try 
                { 
                    
                    Conn.Open(); dr = cmd.ExecuteReader(); 
    把那个conn.open()写到
    SqlConnection Conn = new SqlConnection(Connestr); 
    Conn.Open(); 、、、、、、、、、、、、、、、、、、。。
    SqlDataReader dr; 
    SqlCommand cmd = new SqlCommand(sql,Conn); 
    try 
                { 
                    
                    
      

  10.   

     private static readonly string connestr = ConfigurationManager.ConnectionStringS["GradeSysConnectionString"].ToString(); 
      

  11.   

    15楼的、你通过配置文件读的就是个String类型的、不需要转换.
      

  12.   

    Connestr = "SERVER = (LOCAL); UID = SA; PWD = PWD; DATABASE = NORTHWIND";
    SqlConnection Conn = new SqlConnection(Connestr); 需要先把Connestr赋值
      

  13.   

    SqlConnection Conn = new SqlConnection(Conn); ===============代码不对。 参数应该是  连接字符串。然后,前边一句,该写在这句后边。 sqlcommand对象的实例化得conn之后。