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.
- Create a new Standard EXE project in Visual Basic.
- On the Project menu, click to select References. Add a reference to Microsoft ActiveX Data Objects 2.1 Library (OLEDB).
- 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