Microsoft SQL Server ADOMD. NET supports multidimensional data access in managed applications. ADOMD. NET communicates with the server using the XMLA (XML for Analysis) protocol.
To access a server using Adomd.net, you must meet the requirements:
System Requirements:
Cpu
Intel (Pentium) MHz or higher, Pentium PRO, Pentium II, or Pentium III) or compatible processor
Memory
Minimum 64M memory, recommended 128M memory
Hard disk space: 1M
Operating system:
Microsoft Windows Server 2003
-or-
Microsoft Windows XP with Service Pack 1 (SP1) or later
-or-
Microsoft Windows Server with Service Pack 1 (SP1) or later
-or-
Microsoft Windows NT Server 4.0 with SP6 or later with Msxml3.dll in Replace Mode
Software
* Microsoft. NET Framework Class Library 1.0 SP2 or greater
* MSXML 4.0 or greater (do not ignore this entry)
* AS2000 OLE DB provider required for Microsoft analysis Services 2000
Data access
* An XML for Analysis provider consistent with the XML for analysis
Specification version 1.1, such as the Microsoft XML for analysis Provider
Using Adomd.net Connection Analysis Services 2000:
0 Add a reference to the Microsoft.AnalysisServices.AdomdClient.dll;
After the Adomd.net SDK is installed, the DLL file is located in the X::/program files/microsoft.net/adomd.net/80 directory (x is the disk character).
Add a reference to the DLL file.
Using Microsoft.AnalysisServices.AdomdClient;
1 Establish the connection:
Like Ado.net, to connect an Analysis Services server using Adomd.net, you must establish a Adomdconnection object and a connectionstring connection string. Then call the open or Close method of the Adomdconnection class to turn the connection on or off.
The code is as follows:
String connectionString = "" "Data Source = Jingxiao; Catalog=foodmart 2000; connectto=8.0;integrated Security=sspi ";";
Adomdconnection conn = new adomdconnection ();
Conn. Open ();
Conn. Close ();
Note If the MSXML4.0 or higher version is not installed, the above code will be run with the error box "Unable to establish a connection with the server."
2 Getting metadata for cubes
There are two ways to get metadata for cubes (including dimensions, metrics, hierarchies, and so on):
The first method is obtained by querying the Schemadataset table;
The second method is obtained by adomdconnection the object.
2.1 Get the metadata through Schemadataset (take the metadata of the cube as an example):
Public string[] Getschemadataset_cubes (ref adomdconnection connection,string connectionString)
{
string[] Strcubes = null;
BOOL connected = true; Determine if connection is connected to the database
DataTable objtable = new DataTable ();
if (isconnected (ref connection) = = False)
{
Try
{
Connect (ref connection,connectionstring);
connected = false;
}
catch (Exception err)
{
throw err;
}
}
string[] strrestriction = new String[]{null,null,null};
Objtable = connection. Getschemadataset (adomdschemaguid.cubes,strrestriction). Tables[0];
if (connected = = False)
{
Disconnect (ref connection,false);
}
Strcubes = new String[objtable.rows.count];
int rowcount = 0;
foreach (DataRow temprow in Objtable.rows)
{
Strcubes[rowcount] = temprow["Cube_name"]. ToString ();
rowcount++;
}
return strcubes;
}
2.2 Obtaining metadata through the Adomdconnection object:
Public string[] Getcubes (ref adomdconnection connection,string connectionString)
{
string[] strcubesname = null;
BOOL connected = true; Determine if connection is connected to the database
if (isconnected (ref connection) = = False)
{
Try
{
Connect (ref connection,connection. ConnectionString);
connected = false;
}
catch (Exception err)
{
throw err;
}
}
int rowcount = connection. Cubes.count;
Strcubesname = new String[rowcount];
for (int i=0;i<rowcount;i++)
{
Strcubesname[i] = connection. Cubes[i]. Caption;
}
if (connected = = False)
{
Disconnect (ref connection,false);
}
return strcubesname;
}
Get hierarchies, named sets, and other methods are identical.