Use adomd. Net to obtain analysis services metadata

Source: Internet
Author: User
0. Add a reference to Microsoft. analysisservices. adomdclient. dll;
After the adomd.net SDK is installed, the DLL file is located in the directory X: \ Program Files \ Microsoft. NET \ adomd. Net \ 80 (X is the drive letter ).
Add a reference to the DLL file.
Using Microsoft. analysisservices. adomdclient;
1. Establish a connection:
Similar to ado.net, to connect to the analysis services server using adomd. net, you must create an adomdconnection object and a connectionstring connection string. Call the open or close method of the adomdconnection class to open or close the connection.
Code 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 msxml4.0 or a later version is not installed, an error message is displayed when you run the code above ].

2. Obtain Cube Body metadata
You can use either of the following methods to obtain metadata of a cube (including dimensions, measurements, and layers:
The first method is to query the schemadataset table;
The second method is obtained through the adomdconnection object.
2.1 obtain metadata through schemadataset (taking the metadata of the cube as an example ):
Public String [] getschemadataset_cubes (ref adomdconnection connection, string connectionstring)
{
String [] strcubes = NULL;
Bool connected = true; // determines whether the 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 obtain metadata through the adomdconnection object:
Public String [] getcubes (ref adomdconnection connection, string connectionstring)
{
String [] strcubesname = NULL;
Bool connected = true; // determines whether the 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;
}

The methods for obtaining hierarchies and naming sets are the same.

I wrote a smallProgramWrite an adomdhelper. CS file like the Application Block, and encapsulate some basic metadata retrieval methods (only a small part is completed and will be added later ).

Reference: http://www.cnblogs.com/yiriqing/articles/917032.html

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.