Microsoft KB Archive/245388

= PRB: Attempting to Open Connection with Non-Existent Provider May Succeed =

Article ID: 245388

Article Last Modified on 10/17/2003

-

APPLIES TO


 * Microsoft Data Access Components 2.5
 * Microsoft Data Access Components 2.6

-



This article was previously published under Q245388



SYMPTOMS
While opening a Connection, attempting to specify a non-existent OLE DB provider through the Provider property does not generate an error if the correct provider was previously specified in the ConnectionString argument.



CAUSE
ADO does not recompose the connection string whenever the Provider property is set after specifying the provider in ConnectionString.

The following warning can be found under the Provider Property documentation:

"...; however, specifying a provider in more than one place while calling the Open method can have unpredictable results.... ". NOTE: Previous versions of MDAC components can also exhibit this behavior.



RESOLUTION
Specify the OLE DB provider in only one place before opening your Connection object, preferably via the ConnectionString argument.



STATUS
This behavior is by design.



Steps to Reproduce Behavior
 Start a new Visual Basic Standard EXE project. Form1 is added by default. From the Project menu, click References, and select the "Microsoft ActiveX Data Objects 2.5 Library."  Place the following code in the General Declaration section of Form1: Private Sub Form_Load

Dim cn As New Connection ' Modify the ConnectionString to match your connection parameters cn.ConnectionString = "Provider=SQLOLEDB;Data Source=sequel;User ID=sa;"

cn.Provider = "Invalid_Provider_Name"   ' You can keep this non-existent provider name

cn.Open    '< No error occurs here

MsgBox "done"

End Sub  Run the code and note the behavior.</ol>

<div class="references_section">