Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using Microsoft.AnalysisServices;
- using Microsoft.AnalysisServices.Hosting;
- using Microsoft.AnalysisServices.AdomdClient;
- using System.IO;
- using Newtonsoft.Json;
- using System.Xml;
- using System.Security.Principal;
- namespace ConsoleApplication1
- {
- class ConsoleApplication1
- {
- static void Main(string[] args)
- {
- String ConnStr;
- String OLAPServerName;
- String OLAPDB;
- String OLAPCube;
- String mdxQuery;
- CellSet cst;
- Database CubeDB;
- String filePath;
- OLAPServerName = args[0];
- OLAPCube = args[1];
- mdxQuery = args[2];
- ConnStr = "Provider=MSOLAP;Data Source=" + OLAPServerName + ";";
- //Initial Catalog=Adventure Works DW 2008R2;";
- using (WindowsIdentity.GetCurrent().Impersonate())
- {
- Server OLAPServer = new Server();
- OLAPServer.Connect(ConnStr);
- filePath = AppDomain.CurrentDomain.BaseDirectory + @"\tmp\" + System.IO.Path.GetRandomFileName() + ".json";
- CubeDB = OLAPServer.Databases.GetByName(OLAPCube);
- CubeDB.Process(ProcessType.ProcessFull);
- using (AdomdConnection adomdConnection = new Microsoft.AnalysisServices.AdomdClient.AdomdConnection())
- {
- adomdConnection.ConnectionString = ConnStr;
- AdomdCommand adomdCommand = new Microsoft.AnalysisServices.AdomdClient.AdomdCommand();
- adomdCommand.Connection = adomdConnection;
- adomdCommand.CommandText = mdxQuery;
- adomdConnection.Open();
- System.Xml.XmlReader reader = adomdCommand.ExecuteXmlReader();
- String xml = reader.ReadOuterXml();
- XmlDocument doc = new XmlDocument();
- doc.LoadXml(xml);
- string json = JsonConvert.SerializeXmlNode(doc);
- System.IO.File.WriteAllText(filePath, json);
- reader.Close();
- adomdConnection.Close();
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment