Timeout   expired.请问这是什么错误,我被困扰了好久了.help   me!   thank   you!   
错误信息如下:     
Timeout     expired.         The     timeout     period     elapsed     prior     to     obtaining     a     connection     from     the     pool.         This     may     have     occurred     because     all     pooled     connections     were     in     use     and     max     pool     size     was     reached.  每次实例化个实例conn后,我都有去关闭的conn.close(),但打开网页,查看几次后,总会出现以上的毛病,为什么呢?

解决方案 »

  1.   

    你确定关闭了么?如果泡出异常你的conn也会关闭么?
      

  2.   

    我贴个基类的代码在这里:
    public BaseOpDataBase()
    {
    //
    // TODO: 在此处添加构造函数逻辑
    //
            string constr = System.Configuration.ConfigurationSettings.AppSettings["connstr"];
            
            if (constr == "" || Object.Equals(constr, null))            constr = "Server=" + host + ";UID=" + users + ";PWD=" + password + ";Database=" + database;
            
            connection = new SqlConnection(constr);
            
            try
            {
                connection.Open();
            }
            catch (System.Data.SqlClient.SqlException e)
            {
                throw new Exception(e.Message);
            } }我每次要调用的时候,就实例化 BaseOpDataBase bd = new BaseOpDataBase(),数据操作完成后,就bd.close()掉,为何还会出现那样的错误呢?
      

  3.   

    解决这个问题,需要延长timout的时间,如下:
    SqlConnection conn = new SqlConnection("server=localhost;database=master;uid=;pwd=;Connect Timeout=90");SqlCommand cmd = new SqlCommand(sql, conn);
    cmd.CommandTimeout = 80000;
      

  4.   

    为什么不在
    在finally 中去关闭啊
    try
    {
    .....
    }
    catch()
    {
    ....
    }
    finally
    {
     conn.close();
    }
      

  5.   

    try
            {
                connection.Open();
            }
            catch (System.Data.SqlClient.SqlException e)
            {
                throw new Exception(e.Message);
            } 
    finally
    {
       connection.Close();
    }