Appendix A. Sample KPI Client CodeRetrieving and Exposing Your First KPI


The following code needs to reference Microsoft.AnalysisServices.AdomdClient.dll:

string asConnectionString = "Provider=MSOLAP.3;Data Source=localhost;Initial Catalog=Adventure Works DW"; AdomdConnection asConnection = new AdomdConnection(asConnectionString); try { asConnection.Open();    foreach (CubeDef cubeDef in asConnection.Cubes)       {         if (cubeDef.Properties["CUBE_TYPE"].Value.Equals("CUBE"))            {              string commandText = @"SELECT { strtomember(@Value),                                   strtomember(@Goal),                                   strtomember(@Status),                                   strtomember(@Trend) }              ON COLUMNS FROM [" + cubeDef.Name + "]";              AdomdCommand command = new AdomdCommand(commandText,                                     this.asConnection);              foreach (Kpi kpi in cubeDef.Kpis)              {                 command.Parameters.Clear();                 command.Parameters.Add(new                    AdomdParameter("Value",                    kpi.Properties["KPI_VALUE"].Value));                 command.Parameters.Add(new                    AdomdParameter("Goal",                    kpi.Properties["KPI_GOAL"].Value));                 command.Parameters.Add(new                    AdomdParameter("Status",                    kpi.Properties["KPI_STATUS"].Value));                 command.Parameters.Add(new                    AdomdParameter("Trend",                    kpi.Properties["KPI_TREND"].Value));                 CellSet cellset = command.ExecuteCellSet();                 Debug.WriteLine("KPI Name:" + kpi.Name);                 Debug.WriteLine("Value:" +                    cellset.Cells[0].FormattedValue);                 Debug.WriteLine("Goal:" +                    cellset.Cells[1].FormattedValue);                 Debug.WriteLine("Status:" +                    cellset.Cells[2].FormattedValue);                 Debug.WriteLine("Trend:" +                    cellset.Cells[3].FormattedValue);              }            }       } } finally {     asConnection.Close(); } 





Inside SQL Server 2005 Tools
Inside SQL Server 2005 Tools
ISBN: 0321397967
EAN: 2147483647
Year: 2006
Pages: 149

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net