Each AdomdConnection object has a collection of CubeDef objects that represent the cubes available to the user or application. The CubeDef object exposes information about the cube, as well as various objects related to the cube, such as dimensions, key performance indicators, measures, named sets, and so on.
Whenever possible, you should use the CubeDef object to represent metadata in client applications designed to support multiple OLAP servers, or for general metadata display and access purposes.
The following example uses the CubeDef object to retrieve the visible cubes and their dimensions from the local server:
private string RetrieveCubesAndDimensions()
{
System.Text.StringBuilder result = new System.Text.StringBuilder();
//Connect to the local server
using (AdomdConnection conn = new AdomdConnection("Data Source=localhost;"))
{
conn.Open();
//Loop through every cube
foreach (CubeDef cube in conn.Cubes)
{
//Skip hidden cubes.
if (cube.Name.StartsWith("$"))
continue;
//Write the cube name
result.AppendLine(cube.Name);
//Write out all dimensions, indented by a tab.
foreach (Dimension dim in cube.Dimensions)
{
result.Append("\t");
result.AppendLine(dim.Name);
}
}
//Close the connection
conn.Close();
}
//Return the results
return result.ToString();
}