使用 Server.CreateObject(“ADODB.Connection”) 的经典 ASP 中的连接泄漏

发布于 2024-12-11 22:06:12 字数 756 浏览 0 评论 0原文

我正在查看现有的经典 asp 应用程序。设置如下:

  • db.asp:使用 Server.CreateObject("ADODB.Connection") 打开连接,然后调用 conn.open
  • func.asp:具有帮助程序方法,使用 db.asp 索引中的 conn 对象执行查询
  • 。 asp:构建查询并调用 func.asp 中的方法,

index.asp 和 func.asp 都包含 db.asp。 index.asp 包含 func.asp 没有调用 conn.close 的地方。

  1. 请求结束时连接会自动关闭或恢复吗?
  2. 当index.asp 包含func.asp 时,让index.asp 和func.asp 包含db.asp 有何含义?多个连接?
  3. 是否有任何计数器可以检查正在建立的连接数?

我已经使用过 sp_who2,但即使在不同的浏览器下运行,也只能看到该应用程序的 1 条记录。尝试在连接字符串中使用集成安全性和 SQL 帐户。

我查看了性能计数器,但数字从未改变。它们停留在 5. MSSQL$Instance:General Statistics\Logical Connections 和 MSSQL$Instance:General Statistics\User Connections。

我们看到生产中的应用程序有多达 47 个连接,但我无法在本地重现它。连接被列为睡眠状态,而不是执行状态。

在IIS 7.5下运行经典asp

I'm looking at an existing classic asp application. The setup is as follows:

  • db.asp: opens a connection using Server.CreateObject("ADODB.Connection") and then calls conn.open
  • func.asp: has helper methods to execute queries using the conn object from db.asp
  • index.asp: builds queries and makes calls to methods in func.asp

both index.asp and func.asp include db.asp. index.asp includes func.asp No where is conn.close called.

  1. Will the connections automatically be closed or recovered when the request ends?
  2. What are the implications of having index.asp and func.asp include db.asp when index.asp includes func.asp? Multiple connections?
  3. Are there any counters to check the number of connections being made?

I've already used sp_who2 but only see 1 record for the application even when run under different browsers. tried this using both integrated security and a sql account in the connection string.

I looked in performance counters but the numbers never change. They stay at 5. MSSQL$Instance:General Statistics\Logical Connections and MSSQL$Instance:General Statistics\User connections.

We're seeing up to 47 connections from the app in production but I cannot reproduce it locally. The connections were listed as sleeping, not executing.

Running classic asp under IIS 7.5

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

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

发布评论

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

评论(1

半衬遮猫 2024-12-18 22:06:12
  1. 不,连接保持打开状态,但数据库驱动程序最终会终止它们。不过,这将需要几分钟的时间,因此如果您有大量访问者,您很容易达到并发连接数的数据库限制。
  2. 是的,如果您有多个打开连接的代码,您最终将得到多个连接。如果连接存储在同一个变量中,则对前一个连接的引用将丢失,并且只是保持打开状态等待超时。
  3. 您可以在 SQL Manager 中查看数据库会话。然而,您将不容易看到返回到池的连接和等待超时的孤立连接之间的区别。

您应该确保每个连接和每个记录集都已关闭并取消引用。例子:

rstData.Close
Set rstData = Nothing

conn.Close
Set conn = Nothing
  1. No, the connections are left open, but the database driver will kill them off eventually. It will take several minutes though, so you can easily reach the database limit for the number of concurrent connections if you have a lot of visitors.
  2. Yes, if you have multiple includes for code that opens a connection you will end up with multiple connections. If the connections are stored in the same variable, the reference to the previous connection will be lost, and just be left open waiting for a timeout.
  3. You can look at the database sessions in the SQL Manager. You will however not easily see the difference between connections that are returned to the pool and orphaned connections waiting for a timeout.

You should make sure that every connection and every recordset are closed and dereferenced. Example:

rstData.Close
Set rstData = Nothing

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