strcon有没有问题~检查下~你建立的连接都不存在~~

解决方案 »

  1.   

    是啊
    检查一下strcon,还有看是否有引用System.Data.SqlClient命名空间
      

  2.   

    应该不会呀,ynw506,Joschime 请看,这是我定义的数据库链接string strconn = ("Server=0A0AA309E55F47A;UID=sa;Database=WMS;");   
    SqlConnection cn = new SqlConnection(strconn);   
    cn.Open();
    但是就是打不开呀,急人
      

  3.   

    string strconn = ("Server=0A0AA309E55F47A;UID=sa;PWD=你登陆数据库的密码;Database=WMS;");
      

  4.   

    我想问一下,我在建数据库的时候使用的是windows NT集成安全设置,没有设密码,那么pwd后面应该怎么写?我初学,呵呵,别用鞋子扔我
      

  5.   

    PWD后面什么都不写,但PWD还是要有的
      

  6.   

    还是不行呀,错误信息上面提示还是
    cn.open()有问题
    该我的不是设置有问题呀?
      

  7.   

    “/WMS”应用程序中的服务器错误。
    --------------------------------------------------------------------------------未将对象引用设置到对象的实例。 
    说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。源错误: 
    行 57:  string strconn = ("Server=0A0AA309E55F47A;UID=sa;PWD=;Database=WMS;");   
    行 58:  SqlConnection cn = new SqlConnection(strconn);   
    行 59:  cn.Open();
    行 60: 
    行 61:  /*string strconn= ConfigurationSettings.AppSettings["dsn"];
     源文件: c:\inetpub\wwwroot\wms\default.aspx.cs    行: 59 堆栈跟踪: 
    [NullReferenceException: 未将对象引用设置到对象的实例。]
       LoadLibraryW(UInt16* ) +0
       System.EnterpriseServices.Thunk.Security.Init()
       System.EnterpriseServices.Thunk.Security.SuspendImpersonation()
       System.EnterpriseServices.Platform.Initialize()
       System.EnterpriseServices.Platform.get_W2K()
       System.EnterpriseServices.ResourcePool..ctor(TransactionEndDelegate cb)
       System.Data.SqlClient.ConnectionPool.CreateResourcePool()
       System.Data.SqlClient.ConnectionPool..ctor(DefaultPoolControl ctrl)
       System.Data.SqlClient.PoolManager.FindOrCreatePool(DefaultPoolControl ctrl)
       System.Data.SqlClient.SqlConnectionPoolManager.GetPooledConnection(SqlConnectionString options, Boolean& isInTransaction)
       System.Data.SqlClient.SqlConnection.Open()
       WMS._Default.btn_login_Click(Object sender, EventArgs e) in c:\inetpub\wwwroot\wms\default.aspx.cs:59
       System.Web.UI.WebControls.Button.OnClick(EventArgs e)
       System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
       System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
       System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
       System.Web.UI.Page.ProcessRequestMain() +1277 
    这个是我的错误信息,拜托了
      

  8.   

    用这个替换cn.Open()
    try
    {
      cn.Open()
    }
    catch (Exception ex)
    {
      Console.write(ex.ToString());
    }
      

  9.   

    系统提示system.console没有包括对write的定义,唉
      

  10.   

    恩,刚刚那里是通过了,不过又出来了新的问题说
    这个是错误信息“/WMS”应用程序中的服务器错误。
    --------------------------------------------------------------------------------ExecuteReader 需要打开的并且可用的连接。该连接的当前状态是 Closed。 
    说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.InvalidOperationException: ExecuteReader 需要打开的并且可用的连接。该连接的当前状态是 Closed。源错误: 
    行 77:  SqlCommand cm=new SqlCommand  (mysql,cn);
    行 78:  //执行ExecuteReader ()方法
    行 79:  SqlDataReader dr=cm.ExecuteReader ();
    行 80:  if(dr.Read ())
    行 81:  {
     源文件: c:\inetpub\wwwroot\wms\default.aspx.cs    行: 79 堆栈跟踪: 
    [InvalidOperationException: ExecuteReader 需要打开的并且可用的连接。该连接的当前状态是 Closed。]
       System.Data.SqlClient.SqlCommand.ValidateCommand(String method, Boolean executing)
       System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream)
       System.Data.SqlClient.SqlCommand.ExecuteReader()
       WMS._Default.btn_login_Click(Object sender, EventArgs e) in c:\inetpub\wwwroot\wms\default.aspx.cs:79
       System.Web.UI.WebControls.Button.OnClick(EventArgs e)
       System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
       System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
       System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
       System.Web.UI.Page.ProcessRequestMain() +1277 
    虽然提示错误的是第78行,但感觉应该是这行
    行 77:  SqlCommand cm=new SqlCommand  (mysql,cn);
    有问题吧
      

  11.   

    ExecuteReader 需要打开的并且可用的连接。该连接的当前状态是 Closed。
    cn未打开。
    把你的代码发出来
      

  12.   

    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Web;
    using System.Web.SessionState;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;
    using System.Configuration ;
    using System.Data .SqlClient ;namespace WMS
    {
    /// <summary>
    /// _Default 的摘要说明。
    /// </summary>
    public class _Default : System.Web.UI.Page
    {
    protected System.Web.UI.WebControls.TextBox tbx_uid;
    protected System.Web.UI.WebControls.TextBox tbx_upassword;
    protected System.Web.UI.WebControls.Label lbl_message;
    protected System.Web.UI.WebControls.Button btn_login;

    private void Page_Load(object sender, System.EventArgs e)
    {
    // 在此处放置用户代码以初始化页面
    } #region Web Form Designer generated code
    override protected void OnInit(EventArgs e)
    {
    //
    // CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
    //
    InitializeComponent();
    base.OnInit(e);
    }

    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {    
    this.tbx_uid.TextChanged += new System.EventHandler(this.tbx_uid_TextChanged);
    this.btn_login.Click += new System.EventHandler(this.btn_login_Click);
    this.Load += new System.EventHandler(this.Page_Load); }
    #endregion private void btn_login_Click(object sender, System.EventArgs e)
    {
    //从文件Web.config中读取连接字符串
    string strconn = ("Server=0A0AA309E55F47A;UID=sa;PWD=;Database=WMS;");   
    SqlConnection cn = new SqlConnection(strconn);   
    //cn.Open();
    try
    {
      cn.Open();
    }
    catch (Exception ex)
    {
      Console.Write(ex.ToString());
    }
    /*string strconn= ConfigurationSettings.AppSettings["dsn"];
    //连接本地计算机的WMS数据库
    SqlConnection cn= new SqlConnection (strconn);
    cn.Open ();*/
    //构造SQL语句,该语句在Users表中检查用户名和密码是否正确
    string mysql= "select * from Users where Uid='"+tbx_uid.Text +"'and UPassword='"+tbx_upassword.Text +"'";
    //创建Command对象
    SqlCommand cm=new SqlCommand  (mysql,cn);
    //执行ExecuteReader ()方法
    SqlDataReader dr=cm.ExecuteReader ();
    if(dr.Read ())
    {
    lbl_message.Text= "";
    //保存当前用户名及用户权限
    Session["uid"]=dr["uid"].ToString ();
    Session["upower"]=dr["upower"].ToString ();
    Session["udep"]=dr["udep"].ToString ();
    lbl_message.Text="欢迎您!"+Session["uid"];
    if(Session["upower"].ToString ()=="1")
    { //进入仓库总管界面
    Response.Redirect ("goodsmanage.aspx");
    }
    else if(Session["upower"].ToString ()=="2")
    { //进入分仓库管理员界面
    Response.Redirect ("goodsreserve.aspx");
    }
    else if(Session["upower"].ToString ()=="3")
    { //进入仓库采购员界面
    Response.Redirect ("orderlist.aspx");
    }
    }
    else
    {
    lbl_message.Text ="对不起,您的用户名/密码不正确,请重新输入";
    }
    //关闭连接
    cn.Close();
    } private void tbx_uid_TextChanged(object sender, System.EventArgs e)
    {

    }
    }
    }
      

  13.   

    try
    {
      cn.Open();
    }
    catch (Exception ex)
    {
      Console.Write(ex.ToString());
    }
    /*string strconn= ConfigurationSettings.AppSettings["dsn"];
    //连接本地计算机的WMS数据库
    SqlConnection cn= new SqlConnection (strconn);
    cn.Open ();*/
    //构造SQL语句,该语句在Users表中检查用户名和密码是否正确
    string mysql= "select * from Users where Uid='"+tbx_uid.Text +"'and UPassword='"+tbx_upassword.Text +"'";
    //创建Command对象
    SqlCommand cm=new SqlCommand  (mysql,cn);
    //执行ExecuteReader ()方法
    SqlDataReader dr=cm.ExecuteReader ();替换
    con.Open();
    SqlCommand cmd = con.CreateCommand();
    cmd.CommandText = "select * from Users where Uid='"+tbx_uid.Text +"'and UPassword='"+ tbx_upassword.Text +"'";
    SqlDataReader dr = cmd.ExecuteReader();