Microsoft Knowledge Base Email Alertz

Session pooling can provide high performance in an environment that exhibits frequent connects and disconnects from a backend database. This article describes how to get session pooling in a Visual Basic program that uses ActiveX Data Objec

Search KbAlertz

Advanced Search

Receive Microsoft Knowledge Base articles by E-Mail?

Every night we scan the Microsoft Knowledge Base. If technologies you're interested in are updated, we'll send you an e-mail. You only get one e-mail a day, and only when new articles are added.

Click here to create a
FREE account
Already have an account?
[Click here to Login]











Microsoft Knowledge Base Article

This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks

Article ID: 228843 - Last Review: October 26, 2007 - Revision: 4.3

How To Implement Session Pooling from Visual Basic ADO Program

This article was previously published under Q228843

On This Page

SUMMARY

Session pooling can provide high performance in an environment that exhibits frequent connects and disconnects from a backend database. This article describes how to get session pooling in a Visual Basic program that uses ActiveX Data Objects (ADO) component to talk with the backend database.

MORE INFORMATION

The following Visual Basic program exhibits how you can do session pooling. The trick to doing this is to make sure that one reference to a connection object is retained at global scope in the Visual Basic application. This keeps a reference to the IDataInitialize interface, which is the OLE DB Service Components where session pooling occurs.

Sample Code


Note You must change uid=<username> and pwd=<strong password> to the appropriate username and password before you run this code. Make sure that uid has the appropriate permissions to perform the required operations on the specified database.
'Global connect handle declaration
Dim conn1 As New ADODB.Connection

Private Sub Form_Load()
    Dim conn As New ADODB.Connection
    Dim rs As New ADODB.Recordset
    Dim i As Integer

'Do not uncomment the following. Let time to be default, that is, never 
'expire conn1.CommandTimeout = 60 is not enough to keep connection alive.

    conn1.Open "dsn=pubs;uid=<username>;pwd=<strong password>;"

    For i = 0 To 10
        conn.Open "dsn=pubs;uid=<username>;pwd=<strong password>;"
        rs.Open "select * from authors", conn
        rs.Close
        conn.Close
        Set rs = Nothing
        Set conn = Nothing
    Next

    conn1.Close
    Set conn1 = Nothing

End Sub
				
The preceding ADO program uses the default "MSDASQL" (Microsoft OLEDB Provider for ODBC drivers). To get the required session pooling with this provider you have to change or add the following registry entry:
HKEY_CLASSES_ROOT\CLSID\{c8b522cb-5cf3-11ce-ade5-00aa0044773d}
Look for the value "OLEDB_SERVICES." This is a hex value, and should be set to 0xffffffff to enable ADO session pooling.

If you want to use "SQLOLEDB", the native OLEDB Provider for SQL Server, you have to change/add the following registry entry:
HKEY_CLASSES_ROOT\CLSID\{0C7FF16C-38E3-11d0-97AB-00C04FC2AD98}
Look for the value "OLEDB_SERVICES." Again, this is a hex value and should be set to 0xffffffff to enable ADO session pooling.

Specifying "OLE DB Services=-1;" on the connection string will also use session pooling. If this is set on the connection string it overrides what is set in the registry.

REFERENCES

For additional information, visit the following Microsoft Developer Network (MSDN) Web site:
http://msdn2.microsoft.com/en-us/library/ms810829.aspx (http://msdn2.microsoft.com/en-us/library/ms810829.aspx)

APPLIES TO
  • Microsoft Data Access Components 2.0
  • Microsoft Data Access Components 2.1
  • Microsoft Data Access Components 2.5
  • Microsoft Data Access Components 2.6
  • Microsoft Data Access Components 2.7
Keywords: 
kbproductlink kbhowto kbregistry KB228843
       

Community Feedback System

Very often, it takes hours to solve a problem. Very often, you've looked high and low, and have tried a lot of solutions. When you finally found it, chances are, it was because someone else helped you. Here's your chance to give back. Use our community feedback tool to let others know what worked for you and what didn't.

Please also understand that the community feedback system is not warranted to be correct, it's simply a system that we've built to let people try and help each other. If something in a feedback response doesn't make sense to you, or you're not comfortable making changes that the feedback talks about (like registry edits), please consult a professional.

Thank you for using kbAlertz.com Feedback System.

-- Scott Cate