How to execute a MDX query of SQL Analysis Server in C#

﹥>﹥吖頭↗ 提交于 2019-12-12 16:23:08

问题


I want to execute a SQL Analysis Query in C#. I have successfully connected to Analysis database using the below code:

Server DM_Server = new Server();
Database AS_Database = new Database();
DM_Server.Connect(//SQL Analysis Server Connection String);
AS_Database = DM_Server.Databases[//Database name];

I have a SQL query like

SELECT FLATTENED PredictAssociation()
From
[Mining Structure Name]
NATURAL PREDICTION JOIN
(SELECT (SELECT 1 AS [UserId]) AS [Vm]) AS t 

回答1:


You need to use ADOMD.NET which is the Microsoft.AnalysisServices.AdomdClient namespace. It is also available on Nuget.

AdomdConnection conn = new AdomdConnection(
    "Data Source=localhost;Catalog=YourDatabase");
conn.Open();

string commandText = @"SELECT FLATTENED 
    PredictAssociation()
    From
    [Mining Structure Name]
    NATURAL PREDICTION JOIN
    (SELECT (SELECT 1 AS [UserId]) AS [Vm]) AS t ";
AdomdCommand cmd = new AdomdCommand(commandText, conn);
AdomdDataReader dr = cmd.ExecuteReader();

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

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


来源:https://stackoverflow.com/questions/43436925/how-to-execute-a-mdx-query-of-sql-analysis-server-in-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!