我寫我自己的exe文件在C#中,我可以從命令行運行。也許我的代碼會幫助有類似問題的人。 :)
using Microsoft.AnalysisServices;
string cubeServerName = args[1];
string cubeName = args[2];
Server server = null;
try
{
server = new Server();
server.Connect("Data source=" + cubeServerName + ";Timeout=7200000;Integrated Security=SSPI;");
}
catch (Exception e)
{
return (int)ExitCode.UnknownError;
}
string sqlServerName = args[3];
string user = args[4];
string pass = args[5];
string path = args[6];
string xmlaScript = "";
try
{
xmlaScript = System.IO.File.ReadAllText(@path);
}
catch (Exception e)
{
return (int)ExitCode.InvalidFilename;
}
if (server != null)
{
try
{
int exitCode = 0;
if (xmlaScript != "")
exitCode = ServerExecute(server, xmlaScript);
server.Disconnect();
return exitCode;
}
catch (Exception e)
{
return (int)ExitCode.UnknownError;
}
}
//...
private static int ServerExecute(Server server, string command)
{
XmlaResultCollection results = server.Execute(command);
foreach (XmlaResult result in results)
{
foreach (XmlaMessage message in result.Messages)
{
if (message is XmlaError)
{
Console.WriteLine("ERROR: {0}", message.Description);
return (int)ExitCode.UnknownError;
}
else
{
System.Diagnostics.Debug.Assert(message is XmlaWarning);
Console.WriteLine("WARNING: {0}", message.Description);
}
}
}
return (int)ExitCode.Success;
}
哪個dll或NuGet包你引用你的C#代碼?你提到哪些命名空間?這個「服務器」類駐留在哪個命名空間中? – RBT
@RBT它們看起來像是位於GAC中的Microsoft.AnalysisServices.Core.dll或Microsoft.AnalysisServices.dll。詳情在這裏:https://msdn.microsoft.com/en-us/library/microsoft.analysisservices.aspx – DarcyThomas