Microsoft KB Archive/192644

= FIX: Property Change Through Collection Is Not Effective =

Article ID: 192644

Article Last Modified on 5/17/2007

-

APPLIES TO


 * Microsoft ActiveX Data Objects 1.5
 * Microsoft ActiveX Data Objects 2.0
 * Microsoft ActiveX Data Objects 2.1

-



This article was previously published under Q192644



SYMPTOMS
Setting the properties of a connection's existing ConnectionString, and using the Properties collection prior to connecting may not update the connection string used by the connection object to connect to the database.



CAUSE
If the connection string specifies a property that is set through the Properties collection, the connection string takes precedence.



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

This bug has been fixed in Microsoft ActiveX Data Objects 2.1 Service Pack 2 and later.

You can download Microsoft ActiveX Data Objects from the following site:

http://msdn2.microsoft.com/en-us/data/aa937695.aspx



MORE INFORMATION
 Start a new Standard EXE project. Set a reference to the Microsoft ActiveX Data Objects 2.0 Library. Place a command button on the form.  Paste the following code in the Click event of the command button: Dim cn As New ADODB.Connection

With cn      'Set the initial connection string. 'Following line should be commented to test for the workaround 'in the second test as mentioned in Step 6. .ConnectionString = "Provider=SQLOLEDB;Data Source= ;" & "Initial Catalog=pubs;"

' Following line has to be uncommented when you are commenting ' the preceding line as mentioned in step 6. '.ConnectionString = "Provider=SQLOLEDB;Data Source= " ' If Initial Catalog is not set in connection string, ' it works correctly

'Check which is the current catalog. Debug.Print " Catalog is "; .Properties ("Initial Catalog")

.CursorLocation = adUseClient

'Override connection string with property setting. .Properties("Initial Catalog") = "NorthWind" 'Check which is the current catalog, has it changed? Debug.Print " Catalog is "; .Properties ("Initial Catalog")

'Open the connection. .Open UserID:="sa"

'Check the database that was opened, is it the one you wanted ? Debug.Print " Catalog "; .Properties ("Current Catalog")

End with Set cn = nothing   Execute the program. Even though you attempted to set the Initial Catalog property to the NorthWind database, after opening the connection, the connection string displays Pubs as the database the Initial Catalog.

Results For Setting the "Initial Catalog" Initially

=
================================================== '.ConnectionString = "Provider=SQLOLEDB;Data Source=nuvee;Initial   Catalog=pubs;" ===============================================================

Catalog is pubs

Catalog is northwind

Catalog is pubs

  Comment the line where the .ConnectionString has the Initial Catalog set in the string itself and uncomment the line that does not set the Initial Catalog inline. Execute the program. Results For not Setting the Initial Catalog Initially

=
================================================== '.ConnectionString = "Provider=SQLOLEDB;Data Source=nuvee;" ===============================================================

Catalog is

Catalog is northwind

Catalog is northwind

RESULTS: Now you can connect exclusively to the database. </li></ol>

Keywords: kbado210sp2fix kbbug kbdatabase kbfix kbfix kbmdacnosweep KB192644

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.