ASP.NET连接池问题

发布于 2024-08-30 20:36:08 字数 419 浏览 11 评论 0原文

托管与同一数据库通信的不同 Web 应用程序的两个不同物理服务器上使用的相同连接字符串是否会从同一连接池中提取连接?或者池连接仅限于应用程序级别?

我问这个问题是因为我继承了一个已有 7 年历史的 .NET 1.1 Web 应用程序,该应用程序充满了内联 SQL、未关闭和未处理的 SQL 连接以及 datareader 对象。最近,我的任务是编写一个小型 Web 应用程序,该应用程序托管在另一台服务器上并与同一数据库通信,因此使用相同的数据库连接字符串。我创建了一个 LINQ 对象来读取和写入应用程序所需的一张表。现在,原始 .NET 1.1 应用程序抛出异常,例如

“超时已过期。从池中获取连接之前超时时间已过。发生这种情况的原因可能是所有池连接都在使用中并且已达到最大池大小。”

也许这些是无关的,但想得到你的意见以确保我涵盖了所有的基础。

谢谢!

Does the same connection string used on two different physical servers hosting different web applications that talk to the same database draw connections from the same connection pool? Or are pooled connections confined to at the application level?

I ask because I inherited a 7 year old .NET 1.1 web application which is riddled with in-line SQL, unclosed and undisposed sql connection and datareader objects. Recently, I was tasked to write a small web app that is hosted on another server and talks to the same database and therefore used the same database connection string. I created a LINQ object to read and write the one table required by the app. Now the original .NET 1.1 app is throwing exceptions like

"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."

Maybe these are unreleated, but wanted to get your opinions to make sure I cover all my bases.

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

涫野音 2024-09-06 20:36:08

无法在两台独立的计算机之间汇集连接。但是,您的 SQL Server 对总连接数有连接限制。

发生此错误的原因很可能是应用程序未将连接返回到连接池。发生这种情况的原因是未正确释放连接。发生这种情况的原因可能是代码质量不佳(它是否使用 using 块或 try catch finally?),或者使用 SQLDataReader 可能会导致连接在执行 SQL 的代码退出后保持打开状态。

There is no way connections can be pooled between two separate machines. Your SQL Server will have a connection limit for total connections however.

This error is most likely occurring because the application is not returning connections to the connection pool. This can happen because the connection is not being disposed of correctly. This can happen due to poor code (does it use a using block, or a try catch finally?) or if using a SQLDataReader can cause the connection to stay open after the code to execute the SQL has exited.

一指流沙 2024-09-06 20:36:08

连接池保存在您的应用程序池中,因此单独的计算机不可能从单独的应用程序池中窃取。请查看此处,了解有关连接池的一些信息。我还建议将性能计数器放在 bottom阅读本文,了解更多内容。

还可能想检查 SQL Server 上的最大连接数。在管理工作室
右键单击服务器名称-->属性-->连接

查找“最大并发连接数(0 = 无限制)”

Connection Pools are kept in your App Pool, so it shouldn't be possible for a separate machine to steal out of a separate boxes App Pool. Have a look here for some info on the connection pool. I'd also recommend slapping the performance counters on see bottom of this article to see what's going on in there a bit more.

Also might want to check the max number of connections on SQL Server. In management Studio
Right click on the Server name --> Properties --> Connections

look for "Maximum number of concurrent connections (0 = unlimited)"

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文