Question

I need to retrieve list of members for particular dimension/attribute using AMO (Microsoft.AnalysisService.dll) in .NET 4 project. How do I do that?

I can connect to the server, open the database and see the dimensions, but the Hierarchies collection for the dimension is typically empty, except those dimensions where we defined some hierarchies by hand. That is, default hierarchy is not included.

using Microsoft.AnalysisServices;

var server = new Server();
server.Connect("Data Source=myserver");

var db = server.Databases.FindByName("My Warehouse");
var instrumentDimension = db.Dimensions.FindByName("Instrument");
Console.WriteLine(instrumentDimension.Hierarchies.Count); // prints 0

Going to the cube level does not help, most CubeDimensions also have empty Hierarchies collections.

However, if in Management Studio I issue an XMLA query similar to this:

<Discover xmlns="urn:schemas-microsoft-com:xml-analysis">
  <RequestType>MDSCHEMA_MEMBERS</RequestType>
  <Restrictions>
    <RestrictionList xmlns="urn:schemas-microsoft-com:xml-analysis">
      <CATALOG_NAME>My Warehouse</CATALOG_NAME>
      <CUBE_NAME>My Cube</CUBE_NAME>
      <DIMENSION_UNIQUE_NAME>Instrument</DIMENSION_UNIQUE_NAME>
    </RestrictionList>
  </Restrictions>
  <Properties />
</Discover>

I do get the answer back with a rather bulky XML listing all members. Hence the question: how to retrieve the list of members without resolting to XMLA?

Was it helpful?

Solution

You are connecting via Server connection (AMO) which is the connection used to manage or read the cube structure like you do it from BIDS.

If you want to get data content and not cube structure, you have to use a client connection (Microsoft.AnalysisServices.AdomdClient.AdomdConnection). If you have an open client connection, say clientCon, you can access the schemas like MDSCHEMA_MEMBERS as follows:

AdomdRestrictionCollection restrColl = new AdomdClient.AdomdRestrictionCollection();
restrColl.Add("CATALOG_NAME", "My Warehouse");
restrColl.Add("CUBE_NAME", "My Cube");
restrColl.Add("HIERARCHY_UNIQUE_NAME", "[MyDim].[MyHierarchyName]");
DataSet ds = clientCon.GetSchemaDataSet("MDSCHEMA_MEMBERS", restrColl);
foreach(var row in ds.Tables[0].Rows) {
    // do something with the data
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top