Executing Commands Against an Analytical Data Source

After establishing a connection to an analytical data source, you can use an AdomdCommand object to run commands against and return results from that data source. These commands can retrieve data by using Multidimensional Expressions (MDX), Data Mining Extensions (DMX), or even a limited syntax of SQL. Additionally, you can use Analysis Services Scripting Language (ASSL) commands to modify the underlying database.

Before running a command, you must create it. You can create a command using one of two methods:

The text of the command to be run can be queried and modified using the CommandText property. The commands that you create do not have to return data after they run.

After you have created an AdomdCommand object, there are several Execute methods that your command can use to perform various actions. The following table lists some of these actions.


Use this method

Return results as a stream of data

ExecuteReader to return an AdomdDataReader object

Return a CellSet object


Run commands that do not return rows


Return an XMLReader object that contains the data in an XML for Analysis (XMLA) compliant format


Example of Running a Command

This example uses the AdomdCommand to run an XMLA command that will process the Adventure Works DW cube on the local server, without returning data.

        void ExecuteXMLAProcessCommand()
            //Open a connection to the local server
            AdomdConnection conn = new AdomdConnection("Data Source=localhost");

            //Create a command, and assign it an XMLA command to process the cube.
            AdomdCommand cmd = conn.CreateCommand();
            cmd.CommandText = "<Process xmlns=\"http://schemas.microsoft.com/analysisservices/2003/engine\">\r\n" +
    <DatabaseID>Adventure Works DW Standard Edition</DatabaseID>
    <CubeID>Adventure Works DW</CubeID>

            //Execute the command
            int result = cmd.ExecuteNonQuery();

            //Close the connection

Community Additions