Question Need AdomdCommand examples

gmcconville

New member
Joined
Jul 21, 2015
Messages
2
Programming Experience
10+
Good afternoon.

I am trying to find some information on how to form Adomdcommands. What I would like to do is to retrieve information from our head office server, which I can do fine in Excel, but would like to get basic information, such as Total sales for this year.

This is what I have tried so far.

// Create by Grant McConville
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using Microsoft.AnalysisServices;
using Microsoft.AnalysisServices.AdomdClient;

C#:
    [COLOR=#0000ff][B]public[/B][/COLOR] [COLOR=#000080]partial[/COLOR] [COLOR=#ff0000]class[/COLOR] MainForm : Form
    {
        [COLOR=#0000ff][B]public[/B][/COLOR] [COLOR=#191970][B]MainForm[/B][/COLOR]()
        {
            [COLOR=#191970][B]InitializeComponent[/B][/COLOR]();
            [COLOR=#191970][B]Connect[/B][/COLOR]();
        }
        
        [COLOR=#0000ff][B]public[/B][/COLOR] [COLOR=#ff0000]void[/COLOR] [COLOR=#191970][B]Connect[/B][/COLOR]()
        {
            AdomdConnection conn = [COLOR=#008b8b][B]new[/B][/COLOR] [COLOR=#191970][B]AdomdConnection[/B][/COLOR]();
            conn.ConnectionString = [COLOR=#0000ff]"Provider=MSOLAP.3;Persist Security Info=True;User ID=******;Data Source=*****;Initial Catalog=******"[/COLOR]; // **** = Censored information
            conn.[COLOR=#191970][B]Open[/B][/COLOR]();
            
            AdomdCommand myCommand = [COLOR=#008b8b][B]new[/B][/COLOR] [COLOR=#191970][B]AdomdCommand[/B][/COLOR]();
            myCommand.Connection = conn;
            myCommand.CommandText = [COLOR=#0000ff]"SELECT [Measures].[DLV Sales $ TYR]"[/COLOR];
            
            AdomdDataReader reader = myCommand.[COLOR=#191970][B]ExecuteReader[/B][/COLOR]();
        }
    }

I can open the connection perfectly, but I can an error when I try to execute the reader, saying

Microsoft.AnalysisServices.AdomdClient.AdomdErrorResponseException
at Microsoft.AnalysisServices.AdomdClient.AdomdConnection.XmlaClientProvider.Microsoft.AnalysisServices.AdomdClient.IExecuteProvider.ExecuteTabular(CommandBehavior behavior, ICommandContentProvider contentProvider, AdomdPropertyCollection commandProperties, IDataParameterCollection parameters)
at Microsoft.AnalysisServices.AdomdClient.AdomdCommand.ExecuteReader(CommandBehavior behavior)

Can anyone recommend a website that shows me how to form these commands?

If I use this command in excel, =CUBEVALUE("Cube", "[Measures].[DLV Sales $ TYR]"), it works fine, so I am not sure what I am doing wrong.

The reason I am doing this is I would like to create a basic wages program that automates everything for me.

Thanks in advance
 
Back
Top Bottom