Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

FIX: ADO 2.0: Open Connection May Succeed with Invalid Provider


View products that this article applies to.

This article was previously published under Q245354

↑ Back to the top


Symptoms

If you specify a valid OLE DB provider in the ConnectionString property of a Connection object and then try to specify a provider that does not exist (or is otherwise not registered) on the system in the Provider property of the same Connection object, the Open method of the Connection object succeeds against the original provider.

↑ Back to the top


Resolution

The workaround for this code is to specify the provider in the ConnectionString property or on the Open method.

↑ Back to the top


Status

Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.

This problem is fixed in Microsoft Data Access Components 2.5 (MDAC 2.5). The latest version of MDAC can be obtained from the following Microsoft Web site:

↑ Back to the top


More information

WARNING: Despite the current fix, Microsoft does not recommended that you specify a provider in more than one place while calling the Open method because this behavior might result in unpredictable results.

Steps to Reproduce Behavior

This code only fails on a computer with MDAC 2.1 Service Pack 2 or earlier.
  1. Create a new Standard EXE project in Visual Basic.
  2. On the Project menu, click to select References. Add a reference to Microsoft ActiveX Data Objects 2.1 Library (OLEDB).
  3. Add the following code to your Form1:
    Option Explicit
    
    Private Sub Form1_Load()
       Dim cn as ADODB.Connection
       Set cn = new ADODB.Connection
    
       cn.Open "Provider=SQLOLEDB;Data Source=sqltest;"
       cn.Close
    
       cn.Provider = "InvalidProvider"
       '  The following line will succeed without MDAC 2.5 or higher
       cn.Open
    End Sub
    					

↑ Back to the top


References

For more information, please refer to the Platform SDK for Windows 2000.

↑ Back to the top


Keywords: KB245354, kbmdac250fix, kbfix, kbbug

↑ Back to the top

Article Info
Article ID : 245354
Revision : 5
Created on : 4/22/2003
Published on : 4/22/2003
Exists online : False
Views : 326