我正在尝试编写一个程序来为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
数组,我不知道该怎么做。
感谢您的帮助。
答案 0 :(得分:0)
我终于找到了一些帮助我解决问题的代码。
在代码下面,生成了与我使用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();