我们在使用 SQL Express 运行并处理多个基于 AJAX 的并发请求的 MVC3 Web 应用程序上遇到了 Nhibernate 的一些连接池问题。
每隔一段时间(中间几个小时)我们就会看到错误开始显示:
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.
然后加载
While preparing select TOP (@p0)
....
an error occurred
我们必须回收 IIS 应用程序池以阻止此后抛出 500 个错误。
看看我们看到的SQL Server:
select * from sys.dm_exec_sessions
...给出大约 30 个 ID 大于 51 的 session (即用户 session )
select * from sys.dm_exec_connections
...给出大约相同的数量
但是
select @@connections
...给出 79022 的结果
这是否表明连接永远不会释放?
Nhibernate session 在请求的生命周期内有效。
有没有人有过类似的经验,或者可以为我们指明正确的方向?
非常感谢
理查德
最佳答案
你不能拥有更多 32767连接到 SQL Server。
@@CONNECTIONS也给(我的粗体)
Returns the number of attempted connections, either successful or unsuccessful since SQL Server was last started.
不是当前连接
我怀疑您的池设置不正确,所以用得太快了。
或者您没有正确释放连接并且在回收 IIS 后检查 SQL Server。
关于c# - Nhibernate 连接池问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6643124/