Databases Reference
In-Depth Information
To warn application designers of the potential problem, ADOMD.NET throws an
InvalidOperationException when the client application tries to get properties for which
there is no information on the client. If you really want to access member properties, you
can call the FetchAllProperties method and then use the property you need. Listing
33.23 illustrates this approach.
LISTING 33.23 Fetching the Properties of the Member Object That Are Not Part of a
Multidimensional Result
//Open a connection to the server.
AdomdConnection con = new AdomdConnection(“Datasource=localhost; Initial
Catalog=Foodmart 2008;”);
con.Open();
//Execute an MDX statement.
AdomdCommand command = con.CreateCommand();
command.CommandText = “ SELECT {[Measures].[Store Cost],
[Measures].[Store Sales]} ON COLUMNS FROM [Warehouse and Sales]”;
CellSet cellSet = command.ExecuteCellSet();
//Iterate the axes and tuples on each axis.
foreach(Axis axis in cellSet.Axes)
{
foreach(Tuple tuple in axis.Set.Tuples)
{
Member member = tuple.Members[0];
try
{
//Try to get the member.Type property; this will cause an exception.
Console.WriteLine(member.Type);
}
catch(InvalidOperationException ex)
{
Console.WriteLine(ex.Message);
// Send a request to the server to bring all the properties of
// the current member.
member.FetchAllProperties();
//Successfully print the property member.Type.
Console.WriteLine(member.Type);
}
}
}
//Close the connection
con.Close();
 
Search WWH ::




Custom Search