Connection leaks in Classic ASP using Server.Creat

2019-06-07 02:30发布

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

1条回答
Fickle 薄情
2楼-- · 2019-06-07 02:41
  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
查看更多
登录 后发表回答