超时时间已到。在从池中获取连接之前超时时间已过。出现这种情况可能是因为所有池连接都已被使用并已达到最大池大小(转)...

    如果要返回DataReader的话,在自定义类中打开的Connection应该使用
SqlDataReader sdr = SqlCommandInstance.ExecuteReader(CommandBehavior.CloseConnection);
这样调用者只需要关闭sdr即可,对应的Connection会自动关闭
SqlConnection可设定connection  pool的maxpoolsize和minpoolsize  
 
例如:str_Conn="data  source=ntserver;initial  catalog=gc_web;persist  security  info=true;"+  
                                   "Enlist=true;Pooling=true;Max  Pool  Size=300;Min  Pool  Size=0;Connection  Lifetime=300;user  id=sa;packet  size=4096";  
 
还可以设定SqlCommand.CommandTimeOut  或者Sqlconnection.GeneralTimeOut
这个方法应该是没什么问题吧  
   
  Database   data   =   new   Database();  
  string   strConnection   =   data.DbPath();  
  SqlConnection   objConnection   =   new   SqlConnection(strConnection);  
  objConnection.Open();  
  SqlCommand   objCommand   =   new   SqlCommand(sql,objConnection);  
  SqlDataReader   myReader   =   objCommand.ExecuteReader();  
  this.Repeater5RcPhoto.DataSource   =   myReader;  
  this.Repeater5RcPhoto.DataBind();  
  myReader.Close();  
  objCommand.Dispose();  
  objConnection.Close();


看看微软的写法:  
  Public   Sub   ReadMyData(myConnString   As   String)  
          Dim   mySelectQuery   As   String   =   "SELECT   OrderID,   CustomerID   FROM   Orders"  
          Dim   myConnection   As   New   SqlConnection(myConnString)  
          Dim   myCommand   As   New   SqlCommand(mySelectQuery,   myConnection)  
          myConnection.Open()  
          Dim   myReader   As   SqlDataReader  
          myReader   =   myCommand.ExecuteReader()  
          While   myReader.Read()  
                  Console.WriteLine(myReader.GetInt32(0)   &   ",   "   &   myReader.GetString(1))  
          End   While  
          '   always   call   Close   when   done   reading.  
          myReader.Close()  
          '   Close   the   connection   when   done   with   it.  
          myConnection.Close()  
  End   Sub   'ReadMyData  


解决方法(*):
WEB.config 里面:
在数据库连接加 Max Pool Size = 512;
server=local;uid=;pwd=;database=2004;Max Pool Size = 512;">
一劳永逸。

转载于:https://www.cnblogs.com/cooltonyhawk/articles/1229347.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值