Search code examples
c#visual-studiossasadomd.net

How to structure SSAS project files to execute Adomd on a Cube?


I have created a Cube, and i want to create to execute an MDX query over it through Adomd Client code. I created two files for the purpose inside the SSAS project (where the datasource, view and cube folders are) : one to define a class with the method to execute and another one which represents the main class (Main.cs). My question is how to run the main method and how to structure the project in order to get the cube results ?

My code is :

using System;

public class AdomdCube
{
    

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

        //Create a command, to process the cube.
        AdomdCommand cmd = conn.AdomdCommand("SELECT {[Measures].[Reorder Point]} ON COLUMNS, {[Product].[Product ID]} ON ROWS FROM [Adventure Works]", conn);
        AdomdDataReader dr = cmd.ExecuteReader();

        while (dr.Read())
        {
            Console.WriteLine(Convert.ToString(dr[0]));
        }

        dr.Close();
        conn.Close();
    }
}

and the Main class where i call the previous class is :

using System;
using CubeProcess;
public class Main
{
    static void Main(string[] args)
    {
        CubeProcess.connectAndQueryCube();
        
        
    }
}

My SSAS project structure in VS 2019 is :project structure


Solution

  • The SSAS project is an SSAS project, but what you need is a C# project. You should create a separate e. g. C# console project. You can create it in the same solution like the SSAS project, but it must be a separate project.

    In Visual Studio, one solution can contain several projects, and the solution structure (i. e. mainly the projects which it contains) is contained in a .sln file, while the project configurations are contained in files with a specific extension and format depending on project type. E. g. the structure of a C# project is contained in a .csproj file, and an SSAS project in a .dwproj file.