PRB: Attempting to Open Connection with Non-Existent Provider May Succeed (245388)



The information in this article 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.

MORE INFORMATION

Steps to Reproduce Behavior

  1. Start a new Visual Basic Standard EXE project. Form1 is added by default.
  2. From the Project menu, click References, and select the "Microsoft ActiveX Data Objects 2.5 Library."
  3. 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
    					
  4. Run the code and note the behavior.

REFERENCES

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

Modification Type:MajorLast Reviewed:10/17/2003
Keywords:kbprb KB245388