SQLConnection Pooling - 处理 InvalidOperationException
我正在设计一个高度并发的 CCR 应用程序,在该应用程序中,我必须不阻止或发送线程休眠。
我遇到了 SQLConnection Pool 问题 - 特别是在尝试调用 SqlConnection.Open 时遇到 InvalidOperationExceptions
我可能会重试很多次,但这并不能真正解决问题。
对我来说,理想的解决方案是定期重新检查连接可用性的方法,不需要占用线程
有什么想法吗?
[更新] 以下是发布在 另一个论坛
该解决方案需要手动管理连接池。 我宁愿有一个更动态的解决方案,即在需要时启动
I am designing a Highly Concurrent CCR Application in which it is imperative that I DO NOT Block or Send to sleep a Thread.
I am hitting SQLConnection Pool issues - Specifically getting InvalidOperationExceptions when trying to call SqlConnection.Open
I can potentially retry a hand full of times, but this isn't really solving the problem.
The ideal solution for me would be a method of periodically re-checking the connection for availablity that doesn't require a thread being tied up
Any ideas?
[Update]
Here is a related problem/solution posted at another forum
The solution requires a manually managed connection pool. I'd rather have a solution which is more dynamic i.e. kicks in when needed
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Harry,我在使用 CCR 时也遇到过这个问题。 我的经验是,将调度程序线程与任何 I/O 上的阻塞完全解耦后,我可以比 SqlConnection 池处理的速度快得多地使用和处理工作项。 一旦达到最大池限制,我就遇到了您所看到的那种错误。
最简单的解决方案是预先分配许多非池化异步 SqlConnection 对象并将它们发布到某个中央 Port对象。 目的。 然后,每当您需要执行命令时,请在迭代器中执行以下操作:
使用 Ccr 的好处是,将以下功能添加到这段基本代码中非常简单。
Harry, I've run into this as well, also whilst using the CCR. My experience was that having completely decoupled my dispatcher threads from blocking on any I/O, I could consume and process work items much faster than the SqlConnection pool could cope with. Once the maximum-pool-limit was hit, I ran into the sort of errors you are seeing.
The simplest solution is to pre-allocate a number of non-pooled asynchronous SqlConnection objects and post them to some central Port<SqlConnection> object. Then whenever you need to execute a command, do so within an iterator with something like this:
The nice thing about using the Ccr is that it is trivial to add the following the features to this basic piece of code.
是的,连接保持打开状态并且位于连接池之外。 在上面的示例中,端口是池。
Yes, connections are kept open and out of the connection pool. In the above example, the port is the pool.