2015-10-21 51 views
1

我正在尋找工具或運行xmla腳本的簡單方法(創建或刪除多維數據集的示例)。我曾經使用Inno Setup程序來製作exe文件,在那裏我可以編寫可以像運行命令一樣運行另一個exe文件的命令。從命令行運行xmla文件(Analysis Services)

我發現有這樣的工具,如ascmd.exeReadme For Ascmd Command-line Utility Sample)。但它被用於舊版本的MS SQL。 MS SQL Server 2012和更新版本還有其他嗎?

我可以說我沒有使用ascmd.exe工具,因爲我無法獲得這個工具(我無法從C#編譯項目:Readme For Ascmd Command-line Utility Sample)。

回答

0

我寫我自己的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; 
} 
+0

哪個dll或NuGet包你引用你的C#代碼?你提到哪些命名空間?這個「服務器」類駐留在哪個命名空間中? – RBT

+0

@RBT它們看起來像是位於GAC中的Microsoft.AnalysisServices.Core.dll或Microsoft.AnalysisServices.dll。詳情在這裏:https://msdn.microsoft.com/en-us/library/microsoft.analysisservices.aspx – DarcyThomas

0

我會建議你下載ASCMD_StressTestingScripts(其中包含Ascmd.exe): https://sqlsrvanalysissrvcs.codeplex.com/releases

然後創建在同一目錄Ascmd.exe包含以下內容的Ascmd.exe.config文件。這將導致它使用SQL 2014如果你想SQL 2012,然後更改12.0.0.0到11.0.0.0:

<configuration> 
    <runtime> 
     <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> 
     <dependentAssembly> 
      <assemblyIdentity name="Microsoft.AnalysisServices" publicKeyToken="89845dcd8080cc91" /> 
      <bindingRedirect oldVersion="10.0.0.0" newVersion="12.0.0.0" /> 
      <publisherPolicy apply="no" /> 
     </dependentAssembly> 
     </assemblyBinding> 
    </runtime> 
</configuration>