In this article we will see how to use ADOMD to interact with an Analysis Services cube.

ADOMD.NET is an extension of ADO.NET. It is a data provider Microsoft .NET Framework that is designed to communicate with Microsoft SQL Server Analysis Services.

Using this extension, we can read the multidimensional schema, query cubes, and retrieve results.

Orders or queries ADOMD.NET can be sent in multidimensional expressions MDX, Data Mining extensions (DMX), Analysis Services Scripting Language (ASSL) or even a limited syntax of SQL.

The data provider ADOMD.NET is represented by the Microsoft.AnalysisServices.AdomdClient namespace that is included in the Microsoft.AnalysisServices.AdomdClient.dll located in: "C: \ Program Files \ Microsoft.NET \ ADOMD.NET \ 100."

The following example shows how to use the data provider ADOMD.NET from a client application to retrieve data from the Adventure Works cube using an MDX query that fills a data reader:

Starting by first downloading the AdventureWorks data warehouse and cube, from this lien.

Once the sources are downloaded and deployed, we start by creating a new Console Application project.

Once the project is created, in the Solution explorer tab, you must add a reference to the ADOMD class library that is in this directory: C: \ Program Files \ Microsoft.NET \ ADOMD.NET \ 110

To use this library in our class, we use the namespace:

using Microsoft.AnalysisServices.AdomdClient;

Paste the following code, which allows you to have the sales amount and the gross margin by product category:

Using System; Using System.Data; Using Microsoft.AnalysisServices.AdomdClient; class Program {static void Main (string [] args) {AdomdConnection conn = new AdomdConnection ("Data Source = localhost; Catalog = Adventure Works DW Standard Edition"); conn.Open (); string commandText = "SELECT {[Measures]. [Sales Amount]," + "[Measures]. [Gross Profit Margin] ON COLUMNS," + "{[Product]. [Product Model Categories]. ROWS "+" FROM [Adventure Works] "+" WHERE ([Sales Territory Country]. [United States]) "; AdomdCommand cmd = new AdomdCommand (commandText, conn); AdomdDataReader dr = cmd.ExecuteReader (CommandBehavior.CloseConnection); // output the rows in the DataReader while (dr.Read ()) {for (int i = 0; i <dr.FieldCount; i ++) Console.Write (dr [i] + (i == dr.FieldCount - 1 ? "": ",")); Console.WriteLine (); } dr.Close (); Console.WriteLine (Environment.NewLine + "Press any key to continue."); Console.ReadKey (); }}

The AdomdConnection class represents a connection to a multidimensional data source. The AdomdDataReader class retrieves only, read-only, the data stream from a data source, and is similar to other data reading classes in ADO.NET. The flow of results is returned as soon as the query is executed, allowing access to the data as soon as the first line is available, rather than waiting for all the results to be returned. The AdomdDataReader object is created by calling the Execute () or ExecuteReader () method of the AdomdCommand object. The Read () method of the AdomdDataReader object retrieves the next row of results.

To visualize the result, just run the project:

2 thoughts on "ADOMD.NET?"

  1. You have a Bug in the Labels !! you need a tester to test


    1. Yes, I'm fine, but I'll look like even this bug to fix it. Thank you


Leave a Reply

Your email address Will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment is processed.