The following code demonstrates how to set the ActiveConnection property using a connection string:
Dim cat As New ADOMD.Catalog
cat.ActiveConnection = "Data Source=Bobs Video Store;Provider=msolap;"
The following code demonstrates how to set the ActiveConnection property to an ADO Connection object. You must have a reference to the ADO type library in your project in order to use the ADO Connection object.
Dim dnn As New ADODB.Connection
Dim cat As New ADOMD.Catalog
Cnn.Open " Data Source=Bobs Video Store;Provider=msolap;"
Set cat.ActiveConnection = cnn
Note Remember to use the Set keyword when setting the ActiveConnection property to a Connection object. If you omit the Set keyword you will actually be setting the ActiveConnection property equal to the Connection object's default property: ConnectionString. The code will work; however, you will create an additional connection to the data source, which may have negative performance implications.