通用cube refresh c# script 解决方法:
需要设置的变量如下:
User::varcubename,User::varolapconnstr,User::varolapdbname
Cube 名字,olap连接字符串,和db名字.
这几个变量需要在script task中运用.
Script task中的代码如下,可以根据具体需要做修改:
public void Main() { // TODO: Add your code here Dts.TaskResult = (int)ScriptResults.Success; //User::varolapconnstr,User::varolapdbname var olapconnstr = Dts.Variables["User::varolapconnstr"].Value.ToString(); var olapdbname = Dts.Variables["User::varolapdbname"].Value.ToString(); var olapcubename = Dts.Variables["User::varcubename"].Value.ToString(); //Connect db then process Server _server = new Server(); try { _server.Connect(olapconnstr); if (_server.Connected) { Database _db = _server.Databases.FindByName(olapdbname); //Process dimensions if (_db != null) { foreach (Dimension _dim in _db.Dimensions) { _dim.Process(ProcessType.ProcessFull); } //Process cube if (!string.IsNullOrEmpty(olapcubename)) { Cube _cb = _db.Cubes.FindByName(olapcubename); if (_cb != null) _cb.Process(ProcessType.ProcessFull); } else { //process every cube foreach (Cube _cb in _db.Cubes) { try { _cb.Process(ProcessType.ProcessFull); } catch (Exception ex) { Dts.Events.FireWarning(, "CUBE Refresh", ex.Message, "", ); } } } } } } catch (Exception ex) { Dts.Events.FireWarning(, "CUBE Refresh", ex.Message, "", ); } finally { if(_server.Connected) _server.Disconnect(); } }
如果你只想processdata,则可以在代码里面把cube.processtype改成ProcessData即可.