从命令行运行xmla文件(Analysis Services) [英] Run xmla file (Analysis Services) from command line

查看:197
本文介绍了从命令行运行xmla文件(Analysis Services)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种工具或一种简单的方式来运行xmla脚本(例如创建或删除多维数据集的示例)。我曾经使用 Inno Setup 程序制作exe文件,在那里我可以编写命令来运行另一个exe文件,就像在命令行中一样。

I'm looking for tool or a easy way to run xmla script (example for create or delete cube). I used to make exe file using Inno Setup program and there I can write command which can run another exe file just like in command line.

我发现有这样的工具,例如 ascmd.exe Ascmd命令行实用程序示例的自述文件)。但是它用于旧版本的MS SQL。 MS SQL Server 2012和更高版本是否还有其他功能?

I found that there is such tool such as ascmd.exe (Readme For Ascmd Command-line Utility Sample). But it was used in older versions of MS SQL. Is there any other for MS SQL Server 2012 and newer versions?

我可以说我没有使用 ascmd.exe 工具,因为我无法获得此工具(我无法从此处通过C#编译项目: Ascmd命令行实用程序示例的自述文件)。

I can say that I wasn't use ascmd.exe tool because I wasn't able to get this tool (I couldn't compile the project in C# from here: Readme For Ascmd Command-line Utility Sample).

推荐答案

我用C#编写了自己的exe文件,可以从命令行运行它。也许我的代码可以帮助遇到类似问题的人。 :)

I wrote my own exe file in C# which I can run from command line. Maybe my code will help someone with similar problem. :)

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;
}

这篇关于从命令行运行xmla文件(Analysis Services)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆