INFO: Connection Pool Management by ADO Objects Called From ASPID: Q191572
|
When using ActiveX Data Objects (ADO) within an Active Server Pages (ASP) page, it is important to know how to utilize connection pooling effectively. When using different combinations of implicit and explicit ADO connections with ADO recordsets and commands instantiated with Server.CreateObject or just CreateObject it is possible for the connections to not be returned to the connection pool. The table in the MORE INFORMATION section is a visually depicts possible scenarios and outcomes.
By following a connection type from the left of the grid, and a recordset or command type from the top of the grid, you can find the answers to the
following two questions:
|Recordset |Recordset |Command |Command
|created |created |created |created
|with |with |with |with
|Server. |CreateObject |Server. |CreateObject
|CreateObject | |CreateObject |
-----------------------------------------------------------------------
Explicit |1.Yes |1.Yes |1.Yes |1.Yes
Connection |2.Conn.Close |2.Conn.Close |2.Conn.Close |2.Conn.Close
created with | | | |
Server. | | | |
CreateObject | | | |
-----------------------------------------------------------------------
Explicit |1.Yes |1.Yes |1.Yes |1.Yes
Connection |2.Conn.Close |2.Conn.Close |2.Conn.Close |2.Conn.Close
created with | | | |
CreateObject | | |
---------------------------------------------------------------------------
Implicit |1.No |1.Yes |1.No |1.No
Connection |2.N/A |2.Set |2.N/A |2.N/A
| | Recordset | |
| | = Nothing | |
---------------------------------------------------------------------------
Explicit Connection - Server.CreateObject
sConnect="DRIVER={SQL Server};SERVER=ServerName;DATABASE=Pubs;UID=sa"
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open sConnect
Explicit Connection - CreateObject
sConnect="DRIVER={SQL Server};SERVER=ServerName;DATABASE=Pubs;UID=sa"
Set Conn = CreateObject("ADODB.Connection")
Conn.Open sConnect
Implicit Connection with Recordset
sConnect="DRIVER={SQL Server};SERVER=ServerName;DATABASE=Pubs;UID=sa"
Set Rs = CreateObject("ADODB.Recordset")
Rs.Open "SELECT * FROM Authors", sConnect
Sample ASP page:
<%@ LANGUAGE="VBSCRIPT" %>
<HTML>
<BODY>
>%
dim cn(10)
dim cmd(10)
For x = 0 to 10
Set cn(x) = Server.CreateObject("ADODB.Connection")
cn(x).Open "DRIVER={SQL Server};SERVER=Ovteam;DATABASE=Pubs;UID=sa"
Set cmd(x) = Server.CreateObject("ADODB.Command")
cmd(x).activeconnection = cn(x)
cmd(x).commandtext = "SELECT * FROM Authors"
cmd(x).execute
Response.Write "Command executed: " & x & "<BR>"
Set cmd(x) = Nothing
cn(x).close 'comment this line out to recreate the problem
Set cn(x) = Nothing
Next
%>
</BODY>
<HTML>
For additional information about connection pooling, please see the following article(s) in the Microsoft Knowledge Base:
Q169470 INF: Frequently Asked Questions About ODBC Connection PoolingFor additional information about connectionADO/ASP Scalability, please see the following article(s) in the Microsoft Knowledge Base:
Q176056 INFO: ADO/ASP Scalability FAQ
http://support.microsoft.com/support/default.asp
Additional query words:
Keywords : kbADO kbDatabase kbODBC
Version : WINDOWS:1.5,2.0; winnt:
Platform : WINDOWS winnt
Issue type : kbinfo
Last Reviewed: May 26, 1999