我知道我可能有点晚了,但它来了..
这是 PowerShell,但转换为 C# 是轻而易举的事:
$svrName = "localhost\sql08"
$sourceDB = "Adventure Works DW 2008"
$sourceCube = "Adventure Works"
# load the AMO library (redirect to null to 'eat' the output from assembly loading process)
[System.Reflection.Assembly]::LoadwithpartialName("Microsoft.AnalysisServices") > $null
# connect to the AS Server
$svr = New-Object Microsoft.AnalysisServices.Server
$svr.Connect($svrName)
# get a reference to the database
$db= $svr.Databases.Item($sourceDB)
# get a reference to the cube
$cub = $db.Cubes.FindByName($sourceCube)
# setup the scripter object
$sb = new-Object System.Text.StringBuilder
$sw = new-Object System.IO.StringWriter($sb)
$xmlOut = New-Object System.Xml.XmlTextWriter($sw)
$xmlOut.Formatting = [System.Xml.Formatting]::Indented
$scr = New-Object Microsoft.AnalysisServices.Scripter
# create an array of MajorObjects to pass to the scripter
$x = [Microsoft.AnalysisServices.MajorObject[]] @($cub)
$scr.ScriptCreate($x,$xmlOut,$false)
$sb.ToString() > c:\data\tmpCube2.xmla
# clean up any disposeable objects
$sw.Close()
$svr.Disconnect()
$svr.Dispose()
这不是我的,我是在Darren Gosbell发布的地方找到的。