Original: SSAS Series-"08" Multidimensional data (program shows Cube)
1. Reference dll?
After installing the MS SQL Server installation, you find that the Microsoft.AnalysisServices.AdomdClient namespace was not found in the new project "Add Reference", do you know what the situation is? Had to add the DLL, under "C:\Program files\microsoft.net\adomd.net\100\microsoft.analysisservices.adomdclient.dll" found the file, The last modification time for this file is March 30, 2009, 534KB.
Figure AdomdClient.dll the disk path
2. Connection string?
I think this piece and the ADO is not too big difference, here I use the connection string is: Provider=sqlncli10.1;data source=localhost;integrated security=sspi;initial CATALOG=BPDW; , the string can be found in the data source designer, so there is no need to remember, and you can find it.
Figure Connection String
3, the first program
Code
string Returncommandusingcellset ()
{
//Createa new string builder toStore the results
System.Text. StringBuilder result=new System.Text. StringBuilder ();
//Connect toThe local server
using (Adomdconnection conn=new Adomdconnection ("Provider=SQLNCLI10.1;D ata Source=localhost;integrated Security=sspi;initial Catalog=BPDW; "))
{
Conn.Open();
//Createa command, using this connection
Adomdcommand cmd=Conn. CreateCommand ();
Cmd.commandtext= @"Select {[Measures].[Oil proved reserves]} oncolumns, {[Dim Time].[year].&[ +]} onrows from [BPDW]where [Dim Geography].[Country name].&[Total Asia Pacific]&[ China]";
//Executethe query, returning a Cellset
CellSet CS=cmd. Executecellset ();
//Output thecolumnCaptions fromThe first axis
//Note that thisprocedureassumes a Singlememberexistspercolumn.
Result. Append ("\ t");
Tuplecollection Tuplesoncolumns=cs. Axes[0].Set. tuples;
foreach (Microsoft.AnalysisServices.AdomdClient.Tuplecolumn inchtuplesoncolumns)
{
Result. Append (column. Members[0]. Caption+"\ t");
}
Result. Appendline ();
//Output the row captions fromThe second axis andcell Data
//Note that thisprocedureassumes a-dimensional Cellset
Tuplecollection tuplesonrows=cs. Axes[1].Set. tuples;
for (intRow= 0; row<tuplesonrows.Count; row++)
{
Result. Append (Tuplesonrows[Row]. Members[0]. Caption+"\ t");
for (intCol= 0; Col<Tuplesoncolumns.Count; Col++)
{
Result. Append (CS. Cells[col, Row]. FormattedValue+"\ t");
}
Result. Appendline ();
}
Conn.Close();
returnresult. ToString ();
} //Using Connection
}
SSAS Series-"08" Multidimensional data (program presentation Cube)