c# - Nhibernate连接池问题

原文 标签 c# sql-server nhibernate asp.net-mvc-3 database-connection

Nhibernate Connection Pool Problems

we are having some connection pool issues with Nhibernate on an MVC3 web application which is running with SQL Express and dealing with multiple concurrent AJAX based requests.

Every so often (hours in between) we see errors starting which show:

NHibernate.Util.ADOExceptionReporter
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.

then a load of

While preparing select TOP (@p0)
....
an error occurred

We have to recycle the IIS app pool to stop 500 errors from being thrown after that.

Looking at the SQL Server we see:

select * from sys.dm_exec_sessions

... gives about 30 sessions with IDs above 51 (i.e. user sessions)

select * from sys.dm_exec_connections 

... gives around the same amount

BUT

select @@connections

... gives results with 79022

Is this indicating that the connections are never released?

The Nhibernate sessions are for the lifetime of the request.

Does anyone have any experience of anything like this or can point us in the right direction?

Many thanks

Richard

Answer

You can't have more then 32767 connection to SQL Server.

@@CONNECTIONS also gives (my bold)

Returns the number of attempted connections, either successful or unsuccessful since SQL Server was last started.

Not current connection

I suspect that your pool is not set up correctly so it's exhausted too quickly.

Or you are not releasing connections correctly and you're checking SQL Server after you recycle IIS.

翻译

我们在运行SQL Express并处理多个并发基于AJAX的请求的MVC3 Web应用程序上,Nhibernate出现了一些连接池问题。

每隔一段时间(介于几小时之间),我们就会看到错误开始,这些错误显示:


  NHibernate.Util.ADOExceptionReporter
  超时时间已到。从池中获取连接之前已经过超时时间。这可能是因为所有池化连接都在使用中,并且达到了最大池大小。


然后的负载


  在准备选择TOP(@ p0)时
  ....
  发生错误


我们必须回收IIS应用程序池,以防止在此之后引发500个错误。

查看SQL Server,我们看到:

select * from sys.dm_exec_sessions


...提供约30个ID高于51的会话(即用户会话)

select * from sys.dm_exec_connections 


...给出相同的数量



select @@connections


...以79022给出结果

这是否表明连接从未释放?

Nhibernate会话用于请求的生存期。

有没有人有类似这样的经历或可以为我们指明正确的方向?

非常感谢

理查德
最佳答案
32767与SQL Server的连接不能再多了。

@@CONNECTIONS也给出(我的粗体字)


  返回自上次启动SQL Server以来成功或失败的尝试连接数。


不是目前的连线

我怀疑您的游泳池设置不正确,因此耗尽速度太快了。

或者您没有正确释放连接,并且在回收IIS之后正在检查SQL Server。
相关推荐

c# - C#没有IIS的REST Web服务

c# - 服务器架构

c# - 您如何确定未使用哪些库

c# - 存储变量类型并在运行时使用它创建集合

c# - 如何使用HTML敏捷包注释掉html文档中的所有脚本标签

c# - 添加EventHandler + = EventHandler有什么作用?

c# - 当我使用TimeSpan.Zero作为到期将项目添加到缓存时,会发生什么情况?

c# - 如何在C#中向datagridview行标题添加不同的图标/图像?

c# - 构造函数参数枚举和魔术字符串

c# - 哪种Windows GUI开发工具最适合于学习/掌握?建议/原因