[.net][.net core]如何執行XMLA(xml for analysis)(xmla client)

  • 237
  • 0

[.net][.net core]如何執行XMLA(xml for analysis)(xmla client)

程式碼如下(console):.net還有.net core都通用喔
ps. 程式碼裡面的using都是正確的,但還是稍微補充一下資訊如下
using Microsoft.AnalysisServices; 才是正確的
using Microsoft.AnalysisServices.Core可是錯誤的喔,compile階段就會錯了

using Microsoft.AnalysisServices;
using System;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
			Server OlapServer = new Server();
			string connStrOlap = "Provider=MSOLAP.4; Data Source=http://localhost/olap/msmdpump.dll; Catalog=YourCatalog;";
			OlapServer.Connect(connStrOlap);
			string XMLACommand = @"

<Batch xmlns=""http://schemas.microsoft.com/analysisservices/2003/engine"">
	<Parallel>
		.......Your XML content.......
	</Parallel>
</Batch>
     
                ";
			
			var result = OlapServer.Execute(XMLACommand);
			OlapServer.Disconnect();
			OlapServer.Dispose();
			Console.ReadKey();
        }
    }
}



很重要的一點就是:
如果你的專案是.net,要安裝的nuget package是:
Microsoft.AnalysisServices.AdomdClient.retail.amd64
Microsoft.AnalysisServices.retail.amd64

如果你的專案是.net core,要安裝的nuget package是:
(下面這兩個package在nuget是preview版本,並非正式版)
Microsoft.AnalysisServices.NetCore.retail.amd64 
Microsoft.AnalysisServices.AdomdClient.NetCore.retail.amd64 

參考資料:
https://feedback.azure.com/forums/908035-sql-server/suggestions/35508349-adomd-core
https://social.msdn.microsoft.com/Forums/sqlserver/en-US/57d72b34-9053-41f4-88ec-fcc3ee5703e3/getting-an-error-when-submitting-working-xmla-via-adomdclient-c?forum=sqlanalysisservices
https://stackoverflow.com/questions/54182294/xmla-tmsl-from-net-core
https://stackoverflow.com/questions/53878949/adomd-nuget-package-for-asp-net-core