简体   繁体   English

C#:达到最大池大小的根本原因

[英]C#: Root cause of Max pool size was reached

We are getting following error in our WCF application .我们在WCF 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.这可能是因为所有池连接都在使用中并且达到了最大池大小。

When we received the error at the time total 24 connection were consumed by the application and I think 100 is a default connection pool size.当我们在应用程序消耗了 24 个连接时收到错误时,我认为 100 是默认连接池大小。

We always close the SQL connection and also we dispose the SQLDataReader .我们总是关闭SQL connection并处理SQLDataReader

I am not sure why this execution occurred.我不确定为什么会发生这种执行。 Is there any other situation when we get this error?当我们收到此错误时,还有其他情况吗?

I have some sugestions.我有一些建议。

  1. Implement correctly all connections inside using blocks to close/dispose connections (as you said, this is already done) using块来正确地实现内部的所有连接来关闭/处理连接(正如你所说,这已经完成了)
  2. Check which user/machines are keeping opened connections.检查哪些用户/机器保持打开的连接。 Run this query to identify the database id:运行此查询以识别数据库 ID:

select distinct dbid, DB_NAME(dbid) FROM sys.sysprocesses where dbid > 0

Then, use this query to inspect all opened connections, replacing the dbid :然后,使用此查询检查所有打开的连接,替换dbid

SELECT dbid, DB_NAME(dbid) as DatabaseName, COUNT(dbid) as ConnectionCount, loginame as LoginName
  FROM sys.sysprocesses
 WHERE  dbid = 1
 GROUP BY dbid, loginame
 ORDER BY count(dbid) desc

This can give you some hint about who is keeping too much connections opened.这可以为您提供有关谁保持打开过多连接的一些提示。

  1. Implement pooling in connection string to limit connections.在连接字符串中实现池化以限制连接。 Use this in your application connection string:在您的应用程序连接字符串中使用它:

Pooling=true; Min Pool Size=1; Max Pool Size=5

I hope this can help you.我希望这可以帮助你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM