为 Analysis Services 数据库生成脚本

Generate Script for Analysis Services Database

我正在尝试编写一个程序来为 Analysis Service 服务器上的数据库生成创建脚本。我实现了下面的代码并卡在那里

Server srv = new Server();
srv.Connect(@"DataSource=myservername");
Database db = srv.Databases["MyDatabaseName"];
ScriptInfo scrptInfo = new ScriptInfo(db, 
                       ScriptAction.CreateWithAllowOverwrite, 
                       ScriptOptions.Default, 
                       true);
Scripter scrpt = new Scripter();
XmlWriter xw = XmlWriter.Create(@"C:\temp\scrpt.xml");
scrpt.Script(scrptInfo, xw); // I get syntax error here

但是,我需要在最后一行传递一个 ScriptInfo 的数组,我不知道该怎么做。

感谢您的帮助。

我终于找到了一些帮助我解决问题的代码。

下面的代码生成了与我使用 SSMS 生成的脚本相同的脚本。

Server olapServer = new Server();
olapServer.Connect(@"DataSource=myservername");
Database olapDb = olapServer.Databases.GetByName("MyDatabaseName");

XmlTextWriter xmlWriter = new XmlTextWriter(@"C:\temp\scrpt.xmla", Encoding.UTF8);
xmlWriter.Formatting = Formatting.Indented;
xmlWriter.Indentation = 2;
try
{
    Scripter.WriteCreate(xmlWriter, olapServer, olapDb, true, true);
}
finally
{
    xmlWriter.Close();
}
olapServer.Disconnect();