Connection Example

The following code demonstrates how to set the ActiveConnection property using a connection string. This code assumes there is a Data Source named Bobs Video Store on the OLAP server:

Dim cat As New ADOMD.Catalog
cat.ActiveConnection = "Data Source=Bobs Video Store;Provider=msolap;"

The following code also demonstrates how to set the ActiveConnection property using a connection string. However, this code connects to a local cube file with no connection to an OLAP server:

Dim cat As New ADOMD.Catalog
cat.ActiveConnection = _
"Location=C:\MSDASDK\samples\oledb\olap\data\BobsVid.cub;" + _
"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.