Microsoft SQL Server ADOMD.NET支持在托管应用程序中的多维数据访问。ADOMD.NET使用XMLA(XML for Analysis)协议与服务器进行通讯。 使用ADOMD.NET访问服务器,必须满足一下需求: 系统需求: CPU Intel (Pentium 133 MHz or higher, Pentium PRO, Pentium II, or Pentium III) or compatible processor 内存 最小64M内存,推荐128M内存 硬盘空间:1M 操作系统: Microsoft Windows Server 2003 -or- Microsoft Windows XP with Service Pack 1 (SP1) or later -or- Microsoft Windows 2000 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 软件 * Microsoft .NET Framework Class Library 1.0 SP2 or greater *
MSXML 4.0 or greater (不要忽略此项) * 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 使用ADOMD.NET连接Analysis Services 2000: 0 添加对Microsoft.AnalysisServices.AdomdClient.dll的引用; 安装了Adomd.net SDK后,该dll文件位于x::/Program Files/Microsoft.NET/Adomd.NET/80目录下(x为盘符)。 添加对dll文件的引用。 using Microsoft.AnalysisServices.AdomdClient; 1 建立连接: 与Ado.net类似,要使用ADOMD.NET连接Analysis Services服务器,必须建立一个AdomdConnection对象,以及一个connectionString连接字符串。然后调用AdomdConnection类的Open或者Close方法打开或者关闭连接。 代码如下: string connectionString = ""Data Source = JINGXIAO;Catalog=FoodMart 2000;ConnectTo=8.0;Integrated Security=SSPI";"; AdomdConnection conn = new AdomdConnection(); conn.Open(); conn.Close(); 【注】如果没有安装MSXML4.0或者更高的版本,则运行上述代码的时候,会显示【无法与服务器建立连接的报错框】。 2 获取立方体的元数据 获取立方体(包括维度,度量,层次等)的元数据可以有两种方法: 第一种方法是通过查询SchemaDataSet表来获取; 第二种方法通过AdomdConnection对象来获取。 2.1 通过SchemaDataSet获取元数据(以获取立方体的元数据为例): public string[] GetSchemaDataSet_Cubes(ref AdomdConnection connection,string connectionString) { string[] strCubes = null; bool connected = true; //判断connection是否已与数据库连接 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 通过AdomdConnection对象获取元数据: public string[] GetCubes(ref AdomdConnection connection,string connectionString) { string[] strCubesName = null; bool connected = true; //判断connection是否已与数据库连接 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; } 获取层次,命名集,等方法雷同。 我写了一个小程序,仿照Application Block写了一个AdomdHelper.cs的文件,对一些基本的获取元数据的方法做了一些封装(只完成了一小部分,以后还会不断增加)。
使用ADOMD.NET建立与Analysis Services的连接
最新推荐文章于 2020-12-18 17:28:56 发布