Using the CubeDef Object

Analysis Services Programming

Analysis Services Programming

Using the CubeDef Object

To retrieve cube schema information, use the Microsoft® ActiveX® Data Objects (Multidimensional) (ADO MD) CubeDef object, which exposes the dimensions of the local cube using its Dimensions collection. The Dimensions collection exposes the individual Dimensions, which in turn expose the Hierarchies collection, and so on.

For more information about using the ADO MD CubeDef object to retrieve schema rowsets, see the ADO documentation.

The CubeDef Object Model

The following diagram illustrates the object model used by ADO MD.

Examples
Using ADO MD to Print Member Properties

The following code uses ADO MD to print member properties. This code uses the local cube created by the sample code in Building Local Cubes. This code prints the name and properties of every member of the [Product].[Product Name] level in the cube to the immediate window.

Private Sub Form_Load()
Dim cn As ADODB.Connection
Dim ct As ADOMD.Catalog
Dim cb As ADOMD.CubeDef
Dim dm As ADOMD.Dimension
Dim hr As ADOMD.Hierarchy
Dim lv As ADOMD.Level
Dim mb As ADOMD.Member
Dim pr As ADODB.Property

Set cn = New ADODB.Connection
cn.Open "provider=msolap;data source=c:\warecube.cub"

Set ct = New ADOMD.Catalog
Set ct.ActiveConnection = cn

Set cb = ct.CubeDefs(0)
Set dm = cb.Dimensions("Product")
Set hr = dm.Hierarchies(0)
Set lv = hr.Levels("Product Name")

For Each mb In lv.Members
    Debug.Print mb.Name
    Debug.Print "----------------"
    For Each pr In mb.Properties
        Debug.Print pr.Name & ":  " & pr.Value
    Next pr
    Debug.Print
Next mb
End Sub