通过AMO获取SQL Server SSAS信息

php中文网
发布: 2016-06-07 16:20:48
原创
1516人浏览过

Analysis Management Objects (AMO) 是SQL Server SSAS的对象模型库,通过它可以方便的对SSAS里的对象进行访问及控制,包括Cube,DataSource, DataSourceView, Partition, Measure, Dimension, Assembly, Role以及DataMining对象等。要使用它,必须在机器上找

   analysis management objects (amo) 是sql server ssas的对象模型库,通过它可以方便的对ssas里的对象进行访问及控制,包括cube,datasource, datasourceview, partition, measure, dimension, assembly, role以及datamining对象等。要使用它,必须在机器上找到ssas的安装路径microsoftsql server90sdkassemblies,把目录中的microsoft.analysisservices.dll文件加载到项目的reference列表中,amo对象就是通过这个dll文件进行访问的。

  首先要添加引用using Microsoft.AnalysisServices;

  以下是测试用C#从SSAS中获取部分信息的源码:(代码中已经包含了较多的解释)

  using System;

  using System.Collections.Generic;

  using System.Linq;

  using System.Text;

  using System.Threading.Tasks;

  using Microsoft.AnalysisServices;

  namespace AMOTest

  {

  class Program

  {

  static void Main(string[] args)

  {

  string ConnecteString = "Data Source =ServerName; Provider=msolap";

  Server SSASServer = new Server();

  SSASServer.Connect(ConnecteString);

  List OutDatabase = GetDatabaseCollection(SSASServer);

  //show all database on the server

  Console.WriteLine("-------------Databse-------------------------------");

  for (int i = 0; i

  {

  Console.WriteLine(OutDatabase[i].Name.ToString());

  }

  //show the Cube of a database

  Console.WriteLine("---------------Cube--------------------------------");

  List OutCube = GetCubeCollection(OutDatabase[0]);

  for (int i = 0; i

  {

  Console.WriteLine(OutCube[i].Name.ToString());

  }

  //show all Roles of one database

  Console.WriteLine("---------------Roles_database-------------------------");

  List OutRole = GetRolescollection(OutDatabase[0]);

  Console.WriteLine(OutRole[0].Members.Count);

  //for (int i = 0; i

  //{

  // Console.WriteLine(OutRole[0].Members[i].Name);

  //}

  //show all Roles of one cube

  Console.WriteLine("---------------Roles_Cube----------------------------");

  List OutRole2 = GetRolescollection2(OutCube[0]);

  Console.WriteLine(OutRole2[0].Members.Count);

  //for (int i = 0; i

  //{

  // Console.WriteLine(OutRole2[0].Members[i].Name); //to show the detial of the role Members

  //}

  Console.Read();

  }

  //get the list of the database name

  static public List GetDatabaseCollection(Server server)

  {

  List collectdb = new List();

  foreach (Database db in server.Databases)

  {

  collectdb.Add(db);

  }

  return collectdb;

  }

  //get the list of a database cube name

  static public List GetCubeCollection(Database db)

  {

  List collectcube = new List();

  foreach (Cube cube in db.Cubes)

  {

  collectcube.Add(cube);

  }

  return collectcube;

  }

  //get the list of the database roles

  static public List GetRolescollection(Database db)

  {

  List collectRoles = new List();

  foreach (Role cp in db.Roles)

  {

  collectRoles.Add(cp);

  }

  return collectRoles;

  }

  //get the list of the cube Roles

  static public List GetRolescollection2(Cube cube)

  {

  List collectionRoles = new List();

  foreach (CubePermission cp in cube.CubePermissions)

  {

  collectionRoles.Add(cp.Role);

  }

  return collectionRoles;

  }

  }

  }

  这里需要说明的是,,当我获取Database的Roles和Cube的Roles值时,做了一个对比,他们的值是相同的。这可能的情况是,在Database中Cube只有一个,或者因为Cube隶属于database,他们的Roles值是相同的。

  如下是运行完的截图:

通过AMO获取SQL Server SSAS信息 三联

最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号