I'm trying to write a program to generate creation script for my databases on a Analysis Service server. I implemented below code and have stuck there
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
But, I need to pass an array of ScriptInfo
in the last line and I don't know what to do.
I appreciate your help.
I finally found some codes that helped me to solve my problem.
Below code, generated the same script as I could generate using 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();