Search code examples
asp.netsql-servermdxolapadomd.net

Retrieve data from ASP.NET API by using MDX queries


When I run some of queries on SQL Server, it shows the results, but when I run those same queries via ASP.NET, I couldn't get the results same as SQL Server. I was able to get the table's column names, but couldn't get the data from those rows because my _dt.Rows.Count always is zero.

public dynamic GetData(string business, string email)
{
        string sConnStr = "...";
        string query = "....";

        DataTable _dt = new DataTable();
        AdomdConnection connection = new AdomdConnection(sConnStr);

        connection.Open();

        AdomdCommand cmd = new AdomdCommand(query, connection);

        var data = cmd.ExecuteReader();
        _dt.Load(data);

        return _dt.Columns;
}

Results shows

{
        "AllowDBNull": true,
        "AutoIncrement": false,
        "AutoIncrementSeed": 0,
        "AutoIncrementStep": 1,
        "Caption": ",,,,,,,",
        "ColumnName": ",,,,,,,,",
        "Prefix": "",
        "DataType": "System.Double, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089",
        "DateTimeMode": 3,
        "DefaultValue": null,
        "Expression": "",
        "ExtendedProperties": {},
        "MaxLength": -1,
        "Namespace": "",
        "Ordinal": 0,
        "ReadOnly": true,
        "Table": [],
        "Unique": false,
        "ColumnMapping": 1,
        "Site": null,
        "Container": null,
        "DesignMode": false
    },

like this for all columns.

How can I access the data that shows in SQL Server?

And the another problem is for some queries it throws an exception:

Cannot query internal supporting structures for column '**'[..] because they are not processed. Please refresh or recalculate the table....

seem to same problem that i faced

What is the best way to achieve my results? Thank you


Solution

  • I got the answer

    According to my scenario my organization hadn't gave me proper permissions for apply queries to analysis service.

    According to permissions level that provided by my organization I was able to connect analysis services via my connection string,But that permission level not enough to apply queries to analysis services.

    organization has changed my permission level and now above code working well