使用ADOMD.NET建立与Analysis Services的连接

 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;    
  }
     
获取层次,命名集,等方法雷同。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值