通过AMO获取SQL Server SSAS信息(C#)
Analysis Management Objects (AMO) 是SQL Server SSAS的对象模型库,通过它可以方便的对SSAS里的对象进行访问及控制,包括Cube,DataSource, DataSourceView, Partition, Measure, Dimension, Assembly, Role以及DataMining对象等。要使用它,必须在机器上找到SSAS的安装路径..\MicrosoftSQL Server\90\SDK\Assemblies,把目录中的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<Database> OutDatabase = GetDatabaseCollection(SSASServer);//show all database on the serverConsole.WriteLine("-------------Databse-------------------------------");for (int i = 0; i < OutDatabase.Count; i++){Console.WriteLine(OutDatabase[i].Name.ToString());}//show the Cube of a databaseConsole.WriteLine("---------------Cube--------------------------------");List<Cube> OutCube = GetCubeCollection(OutDatabase[0]);for (int i = 0; i < OutCube.Count; i++){Console.WriteLine(OutCube[i].Name.ToString());}//show all Roles of one databaseConsole.WriteLine("---------------Roles_database-------------------------");List<Role> OutRole = GetRolescollection(OutDatabase[0]);Console.WriteLine(OutRole[0].Members.Count);//for (int i = 0; i < OutRole[0].Members.Count; i++) //to show the detial of the role Members//{// Console.WriteLine(OutRole[0].Members[i].Name);//}//show all Roles of one cubeConsole.WriteLine("---------------Roles_Cube----------------------------");List<Role> OutRole2 = GetRolescollection2(OutCube[0]);Console.WriteLine(OutRole2[0].Members.Count);//for (int i = 0; i < OutRole2[0].Members.Count; i++)//{// Console.WriteLine(OutRole2[0].Members[i].Name); //to show the detial of the role Members//}Console.Read();}//get the list of the database namestatic public List<Database> GetDatabaseCollection(Server server){List<Database> collectdb = new List<Database>();foreach (Database db in server.Databases){collectdb.Add(db);}return collectdb;}//get the list of a database cube namestatic public List<Cube> GetCubeCollection(Database db){List<Cube> collectcube = new List<Cube>();foreach (Cube cube in db.Cubes){collectcube.Add(cube);}return collectcube;}//get the list of the database rolesstatic public List<Role> GetRolescollection(Database db){List<Role> collectRoles = new List<Role>();foreach (Role cp in db.Roles){collectRoles.Add(cp);}return collectRoles;}//get the list of the cube Rolesstatic public List<Role> GetRolescollection2(Cube cube){List<Role> collectionRoles = new List<Role>();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信息(C#)相关推荐
- ssas从mysql获取数据库_通过AMO获取SQL Server SSAS信息
Analysis Management Objects (AMO) 是SQL Server SSAS的对象模型库,通过它可以方便的对SSAS里的对象进行访问及控制,包括Cube,DataSource, ...
- 获取SQL Server数据库增长和收缩事件的详细信息
It is essential for the DBA to need to ensure the SQL Server database performance. Performance tunin ...
- sql 获取数据库字段信息_使用DBATools获取SQL数据库详细信息
sql 获取数据库字段信息 In the series of articles on DBATools, (see TOC at the bottom) we are exploring useful ...
- Always On可用性组中SQL Server统计信息
SQL Server统计信息简介 (Introduction to SQL Server Statistics) SQL Server Statistics are an essential part ...
- 使用系统视图发现SQL Server实例信息
介绍 (Introduction) Out of the box, SQL Server comes with a substantial and – release by release – eve ...
- SQL Server统计信息以及如何在SQL中执行更新统计信息
This article gives a walk-through of SQL Server Statistics and different methods to perform SQL Serv ...
- t–sql pl–sql_不正确SQL Server统计信息– SQL查询性能的杀手–基本知识
t–sql pl–sql 什么是SQL Server统计信息? (What are SQL Server statistics?) SQL Server statistics are a collec ...
- 全废话SQL Server统计信息(2)——统计信息基础
接上文:http://blog.csdn.net/dba_huangzj/article/details/52835958 我想在大地上画满窗子,让所有习惯黑暗的眼睛都习惯光明--顾城<我是一个 ...
- SQL Server统计信息:问题和解决方式
SQL Server统计信息:问题和解决方式 参考文章: (1)SQL Server统计信息:问题和解决方式 (2)https://www.cnblogs.com/yutingliuyl/p/7257 ...
最新文章
- 元数据驱动的微服务架构(上)
- 数据模拟工具wgsim
- Oracle学习笔记之三,Oracle 11g数据库的启动与关闭
- EFCore笔记之异步查询
- 统计某一范围内所有的是K的倍数或者含有K的整数
- Educoder Basemap和Seaborn 第2关:Seaborn图形介绍
- 最新android工程目录下armeabi-v7a,armeabi的具体含义,有什么区别
- 算法学习系列(MCMC):MCMC采样
- ios键盘遮挡输入框问题
- gz是什么意思饭圈_网络语BE是什么意思 饭圈用GE含义出处是哪里还有哪些类似表达...
- Sulley fuzzer learning
- Linux操作系统——切换到root用户及其他用户
- vivado 2018.2官方下载
- 关于OLEDB参数化查询【.net】
- 服务器机器人维修技术,维修机器人
- MIT线性代数笔记四 矩阵的LU分解
- unity开发 斗地主算法—提示AI(提示出牌)
- 怎样从盘面看主力动向
- 蓝桥杯Python刷题
- Games102 学习笔记