Search code examples
c#serviceanalysisolapadomd.net

Microsoft Analysis Services CubeDef from Cube or Cubefrom CubeDef


I'm working on an project to to extract dimensions, measures and kpi from an olap cube.

At this time the prototipe ask dimension from adomdclient:

 connection = new AdomdConnection(connectionString);
 connection.Open();

 Cubes = new List<Cube>();

 foreach (CubeDef def in connection.Cubes)
 {
     if (def.Name[0] == '$')
        continue;
     Cubes.Add(new Cube(def));
 }

And KPI's from AnalysisServices.Server

 server.Connect(ConnectionString);
 Database db = server.Databases[Catalog];
 Cube cube = db.Cubes[catalog];
 foreach (MeasureGroup group in cube.MeasureGroups)
 {
    foreach (Microsoft.AnalysisServices.Measure measure in group.Measures)
    {
         //do the job
    }
}

Because the first return the CubeDef with all the metadata including dimensions,the second one returns the real Cube with all the data including kpi's.

BUT THE CONNETION STRING IS THE SAME!

So there is a way to avoid this shit, open a single connection and retrieve all the necessary data?


Solution

  • Actually, what you can get via the client connection is what client tools normally need (meta data and data itself), while what you get via server connection is related to teh cube definition (like the configuration you do in BIDS). And details about e. g. the data source view or partitions are not needed and thus hidden from clients, as these are only accessible via a server connection.

    To access the KPIs from the client, just use the Kpis property of your CubeDef, which enumerates all KPIs.