惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - Franky
有赞技术团队
有赞技术团队
宝玉的分享
宝玉的分享
雷峰网
雷峰网
Hugging Face - Blog
Hugging Face - Blog
V
V2EX
大猫的无限游戏
大猫的无限游戏
博客园 - 司徒正美
D
Docker
T
The Blog of Author Tim Ferriss
罗磊的独立博客
博客园 - 叶小钗
酷 壳 – CoolShell
酷 壳 – CoolShell
Blog — PlanetScale
Blog — PlanetScale
月光博客
月光博客
J
Java Code Geeks
Jina AI
Jina AI
博客园 - 【当耐特】
C
Check Point Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
腾讯CDC
Last Week in AI
Last Week in AI
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
V
Visual Studio Blog

博客园 - 随风而逝

现况调查的方法及种类 GDP 母版页运行机制 VS2005调试问题解决方案集锦 QQ技术攻略-原来隐藏着这么多秘密 WebService中使用自定义类的解决方法(5种) 英语谚语500句 房产证的作用 五证 10 signs that you’re not cut out to be an IT manager 重新飞翔 你还想熬夜吗? 关于MS数据仓库备份 微软的Analysis Services无法连接 如何使用ADOMD执行OLAP操作 表中某列被修改后触发器SQL例子 如何调试触发器 sql server 2005中的DDL触发器 SQL语句备忘录
使用ADOMD.NET建立与Analysis Services的连接
随风而逝 · 2007-04-10 · via 博客园 - 随风而逝

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的文件,对一些基本的获取元数据的方法做了一些封装(只完成了一小部分,以后还会不断增加)。