连接池已满错误

zqn454654 2011-09-01 06:11:07
Server Error in '/' Application.
--------------------------------------------------------------------------------

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.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: 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.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:


[InvalidOperationException: 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.]
System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +4861594
System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +117
System.Data.SqlClient.SqlConnection.Open() +122
DAL.DBHelper.get_Connection() in D:\zqn\xsj\XSJ\DAL\DBHelper.cs:28
DAL.DBHelper.GetReader(String safeSql) in D:\zqn\xsj\XSJ\DAL\DBHelper.cs:98
DAL.LiuyanbanService.liuyanbanselect() in D:\zqn\xsj\XSJ\DAL\LiuyanbanService.cs:18
BLL.LiuyanbanManager.liuyanbanselect() in D:\zqn\xsj\XSJ\BLL\LiuyanbanManager.cs:15

[TargetInvocationException: Exception has been thrown by the target of an invocation.]
System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) +0
System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) +71
System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks) +350
System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +29
System.Web.UI.WebControls.ObjectDataSourceView.InvokeMethod(ObjectDataSourceMethod method, Boolean disposeInstance, Object& instance) +488
System.Web.UI.WebControls.ObjectDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +1247
System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +19
System.Web.UI.WebControls.DataBoundControl.PerformSelect() +142
System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +73
System.Web.UI.WebControls.GridView.DataBind() +4
System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +82
System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls() +72
System.Web.UI.Control.EnsureChildControls() +87
System.Web.UI.Control.PreRenderRecursiveInternal() +44
System.Web.UI.Control.PreRenderRecursiveInternal() +171
System.Web.UI.Control.PreRenderRecursiveInternal() +171
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +842




--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.3053; ASP.NET Version:2.0.50727.3053


做了一个网站,网站在写程序的机器上,用局域网中机器访问网站就不报错误,把网站放到服务器上就报连接池错误....
...全文
307 28 打赏 收藏 转发到动态 举报
写回复
用AI写文章
28 条回复
切换为时间正序
请发表友善的回复…
发表回复
zqn454654 2011-09-04
  • 打赏
  • 举报
回复
这个问题一个关键的地方大家都没看啊,就是用我写代码的机器当服务器的时候怎么测试都没有连接池的问题,但换到服务器上就出问题
zqn454654 2011-09-04
  • 打赏
  • 举报
回复
[Quote=引用 25 楼 yun15090 的回复:]

下载个SQL helper 很好用的


楼主呢个貌似是北大菜鸟的


关闭程序重新启动就好了
[/Quote]
看来北大青鸟写的程序有特点啊...这也能看出来...
zqn454654 2011-09-04
  • 打赏
  • 举报
回复
[Quote=引用 24 楼 jayrao5566 的回复:]

public static SqlDataReader ExecuteReader(string connectionString, CommandType cmdType, string cmdText, params SqlParameter[] commandParameters)
{
SqlCommand cmd = new SqlComman……
[/Quote]
这个是DBHelper的部分代码吧?有没有全部的啊?
jayrao5566 2011-09-03
  • 打赏
  • 举报
回复
public static SqlDataReader ExecuteReader(string connectionString, CommandType cmdType, string cmdText, params SqlParameter[] commandParameters)
{
SqlCommand cmd = new SqlCommand();
SqlConnection conn = new SqlConnection(connectionString);

// we use a try/catch here because if the method throws an exception we want to
// close the connection throw code, because no datareader will exist, hence the
// commandBehaviour.CloseConnection will not work
try
{
PrepareCommand(cmd, conn, null, cmdType, cmdText, commandParameters);
SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
cmd.Parameters.Clear();
return rdr;
}
catch
{
conn.Close();
throw;
}
}
datareader 关闭 SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);

红魔大卫 2011-09-03
  • 打赏
  • 举报
回复
下载个SQL helper 很好用的


楼主呢个貌似是北大菜鸟的


关闭程序重新启动就好了
zqn454654 2011-09-02
  • 打赏
  • 举报
回复
呃....几年前当过3个月程序员,之后就做电脑相关工作,很少写程序了....现在上司让我弄个内部网站,就把以前弄的DBHelper用了,因为以前用的时候没啥问题,现在我水平相当差了,都是靠以前会的一些东西,上网找代码写....所以我先在基本都不考虑性能了,只要能实现功能就行了....所以我的代码肯定拿不出手的...
各位高手哪位有好点的DBHelper能不能提供给我一个啊~
happytonice 2011-09-02
  • 打赏
  • 举报
回复
关闭数据库连接放在finally里
aykkk 2011-09-02
  • 打赏
  • 举报
回复
大家别嘲笑初学者了,当初都是这样过来的,用datareader没有错,但是记的一定要用完关闭。
推荐使用这样的方式
using(oledbdatareader dr=new oledbdatareader())
{
gridview1.datasource=dr;
gridview1.databind();
}

using(oledbdbconnection conn=new oledbdbconnection(cnstr))
{

}
我用ac数据库的,你可以换成sql的
YiYanXiYin 2011-09-02
  • 打赏
  • 举报
回复
connection = new SqlConnection(connectionString);
if (connection == null)
{
connection.Open();
}
楼主也代码的时候一定在梦游吧
蔡袅 2011-09-02
  • 打赏
  • 举报
回复
DataReader 读取流很容易导致连接线程池满了。
酷儿 2011-09-02
  • 打赏
  • 举报
回复
呵呵 a
行游客 2011-09-02
  • 打赏
  • 举报
回复
看看,是不是你每做一种操作,都要连好多次数据库,要是这样的话,你得优化优化你的代码了。
Jeff090116 2011-09-02
  • 打赏
  • 举报
回复
你这问题我遇到过,你是不是使用的datareader做查询的?如果是,改成dataset吧,要不问题很大
Im_Sorry 2011-09-02
  • 打赏
  • 举报
回复
你都返回datareader 就证明你没关闭连接! 应该在返回之前关闭,


我只能说你代码很烂~ 多找找把, 肯定是关闭连接出错了!

  • 打赏
  • 举报
回复
[Quote=引用 10 楼 zqn454654 的回复:]
改过了 改到512够大了吧[/Quote]

这里我再忠告你一个程序员生存之道。遇到这种找bug的时候,你应该把这个参数调得尽可能小,这样才能尽快找出程序中的bug,然后你的程序才应该使用正常的参数(因为这是开发者大量测试过、认为比较合理和高效的)来运行。

csdn上的意见你一定要用自己的头脑来判断。
  • 打赏
  • 举报
回复
这代码,烂得可以。随便挑出几条:

           private static SqlConnection connection;
public static SqlConnection Connection
{
get
{
string connectionString = ConfigurationManager.AppSettings["constr"].ToString();
connection = new SqlConnection(connectionString);
这里用得着额外再去声明一个 private static 的变量吗?


               catch (Exception e)
{
return "0";
}
connection.Close();

}
晕啊,想当然地返回一个"0",这是要混淆正常的输出跟异常的区别吗?而且抛出异常时最后一句又怎么可能执行到?


而下一个catch{ return 0;} connection.Close();代码也是如此。


下面几个方法更加离谱
               return reader;
reader.Close();
reader.Dispose();
这类代码你竟然连续写了三次!


再回到你开头的两个ExecuteCommand方法,怎么就没有跟下边似地(虽然错误但是)想到了connection.Close() 呢?


最后,程序执行中遇到抛出任何异常的地方,其实都没有关闭Connection。可见你没有了解过Using(){...}语法。
liuyang509 2011-09-02
  • 打赏
  • 举报
回复
帮 顶
hmhhmhhmh 2011-09-02
  • 打赏
  • 举报
回复
我也是出现了这样的错误,后来我把常用的连接都放入缓存中了,就没有出错了。
你可以这样测试,设置几个全局变量,打开了几个,关闭了几个,最后对比一下。
zqn454654 2011-09-02
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 sh524555685 的回复:]

改一下连接字符串的Max Pool Size这个属性,改大点试试。
[/Quote]

改过了 改到512够大了吧
行游客 2011-09-02
  • 打赏
  • 举报
回复
改一下连接字符串的Max Pool Size这个属性,改大点试试。
加载更多回复(8)

62,041

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧