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.
我的链接都关闭了,可还是有这个问题,怎么回事啊?有时候也会报这个错误.ExecuteReader requires an open and available Connection. The connection's current state is connecting
在本地测试没问题,传到服务器上偶尔会出现这样的情况,这是服务器编译问题还是我的代码有问题,谁能给我个sqldatareader方法!

解决方案 »

  1.   

    又一个Connection Leak问题,检查是否有数据库操作没有及时关闭连接
      

  2.   

    另外记得,即使你使用了企业库,对于sqldatareader,也是要加using的,否则程序不会自动关闭连接。
      

  3.   

    没有关闭datareader  自己检查下吧,再就是  最好在本地搭建一个模拟服务器,像这样的问题一下子就查出来了,datareader速度是快 但是要注意及时关闭才行,要不就别用
      

  4.   

    连接都关闭了啊这是我的方法:
            public static newtype getAllnewtypeByid(int newtypeid)
            {
                newtype objnewtype = null;
                string sql = "select * from newtype where newtypeid=@newtypeid";
                SqlDataReader reader = DBHelp.GetReader(sql, new SqlParameter("@newtypeid", newtypeid));
                try
                {                if (reader.Read())
                    {
                        objnewtype = new newtype();
                        objnewtype.Newtypeid = (int)reader["newtypeid"];
                        objnewtype.Typename = (string)reader["typename"];
                    }
                }
                catch
                {
                    return null;
                }
                finally
                {
                    reader.Close();
                    reader.Dispose();
                }
                return objnewtype;
            }帮忙看看对不?
      

  5.   

    reader.Close()会导致connection也close吗?这个没有研究,保险点用using吧,MS的例子都是用using的
      

  6.   

    我不用dataReader很久了。用dataSet把 去找个dataSet的DBHelper吧
      

  7.   

    你查看下你的DBHelp 有没将connection关了。
      

  8.   

    dataReader带来的一点性能几乎可以忽略不计,用dataSet吧!