The information in this article applies to:
SUMMARY
CnPool.exe contains a sample Visual Basic project that is used to
demonstrate how Connection Pooling and Prepared Statements affect the scope
and duration of temporary objects within Tempdb. This sample project might
be useful in understanding the scope and longevity of temporary objects
with Connection Pooling and/or Prepared Statements enabled.
MORE INFORMATIONThe following files are available for download from the Microsoft
Download Center. Click the file names below to download the files: Cnpool.exeRelease Date: JUN-10-1998 For more information about how to download files from the Microsoft Download Center, please visit the Download Center at the following Web address http://www.microsoft.com/downloads/search.aspand then click How to use the Microsoft Download Center. How to Run the Sample ApplicationBefore running the sample application you must register ODBCw32.dll using the Regsvr32.exe utility. To do this, click Run on the Start menu. When the Run dialog box appears, type the following command and click OK:
To examine Connection Pooling in more detail, open the code sample project
in Visual Basic design mode. If you get an error when you attempt to run
the Visual Basic project in design mode, reselect the reference to
ODBCw32.dll (Project-References).
NOTE: The code sample depends on the Pubs database by default. Make the appropriate changes in the connection string for your specific environment. Before running the Visual Basic application, run the SQL Client utility ISQL/w. In ISQL/w, change the database to Tempdb and type the following in the query command window:
Enable Connection Pooling and Disable Prepared StatementsNow you are ready to run the code sample.
Disable Connection Pooling and Disable Prepared Statements
Enable Connection Pooling and Enable Prepared Statements
Because we use a prepared statement, the #temp table is created within the scope of a stored procedure and, though Connection Pooling is enabled, the stored procedure goes out of scope and is dropped when the connection is closed in Visual Basic. Because the #temp table created by the stored procedure only exists within the scope and duration of the stored procedure, it is also dropped. For additional information, please see the following article in the Microsoft Knowledge Base: Q151536 INF: SQLPrepare and Temporary Stored Procedures in SQL ServerYou can repeat the previous steps and experiment with different combinations of Connection Pooling and Prepared Statements. If you first execute the statement as a prepared statement and then you open a new connection (without closing the original connection) and execute the statement as a non-prepared statement, another connection is created. The #odbc# object disappears but the #temp object does not. ConclusionIn conclusion, you can avoid some overlapping in the Tempdb that occurs during the creation of temporary tables and other state variables when Connection Pooling is enabled, if you execute the statements within a stored procedure or if you execute prepared statements, for example, ADO - Command.Prepared = True. You can trap the error in code when you attempt to create the temporary table as a prepared statement if you open a new connection (without closing the current connection) and execute the statement. Note that another connection is opened and the connection that caused the temporary object conflict is out of scope for this connection, and the statement should execute normally. Otherwise, you can wait for the default connection timeout of 60 seconds and try again.Experiment with Connection Pooling with the sample application to gain a better understanding of how Connection Pooling affects the Tempdb environment and how you can avoid overlapping results. REFERENCESFor additional information, please see the following articles in the Microsoft Knowledge Base: Q151536 INF: SQLPrepare and Temporary Stored Procedures in SQL Server Q155818 INF: Cannot SQLPrepare() the Creation of Temporary Objects For additional information about advanced features of ActiveX Data Objects (ADO), please see the following article in the Microsoft Knowledge Base: Q169470 INF: Frequently Asked Questions About ODBC Connection Pooling Information is also available by querying for the phrase "Connection Pooling" in Microsoft Developer Network (MSDN). Additional query words: prodsql
Keywords : kbfile kbsample kbSQL kbVBp500 |
Last Reviewed: December 16, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |