c# - 检索多维数据库对象目录

标签 c# sql-server ssis ssas olap

我正在尝试列出在 SSAS 服务器中找到的所有对象(多维数据集、维度、分区...)。我可以使用以下项目来做到这一点:

我正在尝试为每个对象检索相关目录(在数据目录中)。我无法这样做,因为文件名包含一些增量数字,每次您对数据库中的对象进行更改时,这些数字都会更改。示例:

  • 立方体名称:TestCube

文件夹:

|Data Dir|\<SSASDB>\TestCube.0.cub

在更改和重新处理 Cube 后,它更改为另一个值

|Data Dir|\<SSASDB>\TestCube.1.cub

AMO 类中是否有返回每个对象的文件夹路径的属性?文件夹名称中包含的增量编号的值是多少?是否有一些解决方法可以做到这一点?


因为我只安装了 SQL Server Data Tools 商业智能工具,所以我需要一个与 SSIS 脚本任务 兼容的解决方案,因为这是我处理数据的唯一方式。注意这里有 many articles online for using AMO from script task

环境:SQL Server 2014

最佳答案

既然您以立方体为例,这意味着您使用的是多维模型而不是表格。

SSAS 数据目录内容层次结构

在使用 SSAS 构建多个多维立方体之后,我可以假设以下树是数据目录层次结构:

|- Data Directory
    |- Database (.db)
        |- Dimension (.dim)
        |- Role (.role)
        |- Mining Structure (.dms)
        |- Data Source (.ds)
        |- Data Source View (.dsv)
        |- Multidimensional Cube (.cub)
            |- Measure Group (.det)
                |- Partition (.prt)
                |- AggregationDesign (.agg)

上面树中的每个对象都可以以目录或/和 XML 文件的形式存储。

Actions 和 Kpis 信息存储在 Cube XML 配置文件中。

示例:

  • 对象:立方体
  • 目录:<DataDir>\<database>\<cube ID>.cub\
  • XML 文件:<DataDir>\<database>\<cube ID>.cub.xml

将 SSAS AMO 对象链接到数据目录文件

使用AMO读取数据

为了从部署的 Analysis Cube 中读取 SSAS 对象,我改进了以下项目的代码以添加更多对象并将它们与相关目录/文件链接。

更新方法

要将每个 AMO 对象映射到相关目录/XML 文件,我们必须从顶层(数据库)开始遍历对象并检索在每个级别中找到的文件/目录,并使用 .ID 属性和扩展名(如上面的树中提到的那样)

以下代码是用 C# 编写的,是上面链接中发布的方法的更新版本:

请注意,该方法仅适用于本地服务器,或者您必须具有与包含数据目录的原始驱动器相同盘符的映射网络驱动器。此外,您必须具有访问分析服务器对象的权限

代码被视为概念证明,可以改进

SSAS对象类

public class SSASObject
{

    public enum ObjectType{

        Cube = 0,
        MeasureGroup = 1,
        Dimension = 2,
        Partition = 3,
        AggregationDesign = 4,
        MiningStructure = 5,
        Role = 6,
        DataSource = 7,
        DataSourceView = 8,
        Database = 9,
        Server = 10,
        Kpi = 11,
        Action = 12

    }

    public int ID { get; set; } //incremental ID 
    public int? ParentID { get; set; } // Parent incremental ID
    public ObjectType Type { get; set; } // The Object type
    public string ObjectID { get; set; } // Object ID defined in SSAS
    public string ObjectName { get; set; } // Object Name defined in SSAS
    public string Extension { get; set; } // The Object extension
    public string FolderPath { get; set; } // The Object related directory
    public string FolderName { get; set; } // The directory name
    public DateTime? FolderModifiedDate { get; set; } // The directory last modified date
    public string FolderIncremetalID { get; set; } // The Incremental Number mentioned in the directory name
    public string XMLFilePath { get; set; } // The Object related XML file
    public string XMLFileName { get; set; } // The XML file name
    public DateTime? XmlModifiedDate { get; set; } // The XML file last modified date
    public string XmlIncremetalID { get; set; }  // The incremental number mentioned in the XML file name      


}

SSASAMO 类

public static class SSASAMO
{
    public static List<SSASObject> ReadMeta(string ServerName)
    {
        try
        {


            List<SSASObject> result = new List<SSASObject>();

            String ConnStr;

            DateTime? dt = null;
            int idx = 0;
            int DbID = 0;
            int CubeID = 0;
            int ObjectID = 0;

            string DataDir;
            string OLAPServerName = ServerName;

            ConnStr = "Provider=MSOLAP;Data Source=" + OLAPServerName + ";";

            Server OLAPServer = new Server();
            OLAPServer.Connect(ConnStr);

            DataDir = OLAPServer.ServerProperties["DataDir"].Value;

            string[] DatabasesDir = System.IO.Directory.GetDirectories(DataDir, "*", System.IO.SearchOption.TopDirectoryOnly);
            string[] DatabasesFiles = System.IO.Directory.GetFiles(DataDir, "*", System.IO.SearchOption.TopDirectoryOnly);

            result.Add(new SSASObject
            {
                ID = idx,
                ParentID = null,
                FolderModifiedDate = System.IO.Directory.GetLastWriteTime(DataDir),
                FolderPath = DataDir,
                ObjectName = OLAPServerName,
                Type = SSASObject.ObjectType.Server
            });

            // Database
            foreach (Database OLAPDatabase in OLAPServer.Databases)
            {


                string CurrentDbDir = DatabasesDir.Where(x => x.StartsWith(DataDir + "\\" +  OLAPDatabase.ID.ToString() + ".") && x.EndsWith(".db")).DefaultIfEmpty("").First();
                string CurrentDbXmlFile = DatabasesFiles.Where(x => x.StartsWith(DataDir + "\\" + OLAPDatabase.ID.ToString() + ".") && x.EndsWith(".db.xml")).DefaultIfEmpty("").First();

                string[] DbObjectsDir = System.IO.Directory.GetDirectories(CurrentDbDir, "*", System.IO.SearchOption.TopDirectoryOnly);
                string[] DbObjectsFiles = System.IO.Directory.GetFiles(CurrentDbDir, "*", System.IO.SearchOption.TopDirectoryOnly);


                idx++;
                DbID = idx;
                result.Add(new SSASObject
                {
                    ID = idx,
                    ParentID = 0,
                    ObjectID = OLAPDatabase.ID,
                    FolderModifiedDate = CurrentDbDir == "" ? dt : System.IO.Directory.GetLastWriteTime(CurrentDbDir),
                    XmlIncremetalID = System.IO.Path.GetFileNameWithoutExtension(
                                                  System.IO.Path.GetFileNameWithoutExtension(CurrentDbXmlFile)).Substring(
                                                  System.IO.Path.GetFileNameWithoutExtension(CurrentDbXmlFile).IndexOf(".") + 1),
                    Extension = ".db",
                    FolderName = System.IO.Path.GetFileName(CurrentDbDir),
                    FolderPath = CurrentDbDir,
                    ObjectName = OLAPDatabase.Name,
                    Type = SSASObject.ObjectType.Database,
                    XMLFileName = System.IO.Path.GetFileName(CurrentDbXmlFile),
                    XMLFilePath = CurrentDbXmlFile,
                    XmlModifiedDate = CurrentDbXmlFile == "" ? dt : System.IO.File.GetLastWriteTime(CurrentDbXmlFile),
                    FolderIncremetalID = System.IO.Path.GetFileNameWithoutExtension(CurrentDbDir).Substring(
                                                  System.IO.Path.GetFileNameWithoutExtension(CurrentDbDir).IndexOf(".") + 1)
                });



                //Data Source
                foreach (DataSource OLAPDataSource in OLAPDatabase.DataSources)
                {
                    idx++;
                    string CurrentDataSourceDir = DbObjectsDir.Where(x => x.StartsWith(CurrentDbDir + "\\" + OLAPDataSource.ID.ToString() + ".") && x.EndsWith(".ds")).DefaultIfEmpty("").First();
                    string CurrentDataSourceXmlFile = DbObjectsFiles.Where(x => x.StartsWith(CurrentDbDir + "\\" + OLAPDataSource.ID.ToString() + ".") && x.EndsWith(".ds.xml")).DefaultIfEmpty("").First();
                    result.Add(new SSASObject
                    {
                        ID = idx,
                        ParentID = DbID,
                        ObjectID = OLAPDataSource.ID,
                        FolderModifiedDate = CurrentDataSourceDir == "" ? dt : System.IO.Directory.GetLastWriteTime(CurrentDataSourceDir),
                        XmlIncremetalID = System.IO.Path.GetFileNameWithoutExtension(
                                                      System.IO.Path.GetFileNameWithoutExtension(CurrentDataSourceXmlFile)).Substring(
                                                      System.IO.Path.GetFileNameWithoutExtension(CurrentDataSourceXmlFile).IndexOf(".") + 1),
                        Extension = ".ds",
                        FolderName = System.IO.Path.GetFileName(CurrentDataSourceDir),
                        FolderPath = CurrentDbDir,
                        ObjectName = OLAPDataSource.Name,
                        Type = SSASObject.ObjectType.DataSource,
                        XMLFileName = System.IO.Path.GetFileName(CurrentDataSourceXmlFile),
                        XMLFilePath = CurrentDataSourceXmlFile,
                        XmlModifiedDate = CurrentDataSourceXmlFile == "" ? dt : System.IO.File.GetLastWriteTime(CurrentDataSourceXmlFile),
                        FolderIncremetalID = System.IO.Path.GetFileNameWithoutExtension(CurrentDataSourceDir).Substring(
                                                      System.IO.Path.GetFileNameWithoutExtension(CurrentDataSourceDir).IndexOf(".") + 1)
                    });


                }

                //Data Source View
                foreach (DataSourceView OLAPDataSourceView in OLAPDatabase.DataSourceViews)
                {
                    idx++;
                    string CurrentDataSourceViewDir = DbObjectsDir.Where(x => x.StartsWith(CurrentDbDir + "\\" + OLAPDataSourceView.ID.ToString() + ".") && x.EndsWith(".dsv")).DefaultIfEmpty("").First();
                    string CurrentDataSourceViewXmlFile = DbObjectsFiles.Where(x => x.StartsWith(CurrentDbDir + "\\" + OLAPDataSourceView.ID.ToString() + ".") && x.EndsWith(".dsv.xml")).DefaultIfEmpty("").First();
                    result.Add(new SSASObject
                    {
                        ID = idx,
                        ParentID = DbID,
                        ObjectID = OLAPDataSourceView.ID,
                        FolderModifiedDate = CurrentDataSourceViewDir == "" ? dt : System.IO.Directory.GetLastWriteTime(CurrentDataSourceViewDir),
                        XmlIncremetalID = System.IO.Path.GetFileNameWithoutExtension(
                                                      System.IO.Path.GetFileNameWithoutExtension(CurrentDataSourceViewXmlFile)).Substring(
                                                      System.IO.Path.GetFileNameWithoutExtension(CurrentDataSourceViewXmlFile).IndexOf(".") + 1),
                        Extension = ".dsv",
                        FolderName = System.IO.Path.GetFileName(CurrentDataSourceViewDir),
                        FolderPath = CurrentDbDir,
                        ObjectName = OLAPDataSourceView.Name,
                        Type = SSASObject.ObjectType.DataSourceView,
                        XMLFileName = System.IO.Path.GetFileName(CurrentDataSourceViewXmlFile),
                        XMLFilePath = CurrentDataSourceViewXmlFile,
                        XmlModifiedDate = CurrentDataSourceViewXmlFile == "" ? dt : System.IO.File.GetLastWriteTime(CurrentDataSourceViewXmlFile),
                        FolderIncremetalID = System.IO.Path.GetFileNameWithoutExtension(CurrentDataSourceViewDir).Substring(
                                                      System.IO.Path.GetFileNameWithoutExtension(CurrentDataSourceViewDir).IndexOf(".") + 1)
                    });


                }


                //Dimension
                foreach (Dimension OLAPDimension in OLAPDatabase.Dimensions)
                {

                    idx++;
                    string DimensionDir = DbObjectsDir.Where(x => x.StartsWith(CurrentDbDir + "\\" + OLAPDimension.ID.ToString() + ".") && x.EndsWith(".dim")).DefaultIfEmpty("").First();
                    string DimensionXmlFile = DbObjectsFiles.Where(x => x.StartsWith(CurrentDbDir + "\\" + OLAPDimension.ID.ToString() + ".") && x.EndsWith(".dim.xml")).DefaultIfEmpty("").First();

                    result.Add(new SSASObject
                    {
                        ID = idx,
                        ParentID = DbID,
                        ObjectID = OLAPDimension.ID,
                        FolderModifiedDate = DimensionDir == "" ? dt : System.IO.Directory.GetLastWriteTime(DimensionDir),
                        XmlIncremetalID = System.IO.Path.GetFileNameWithoutExtension(
                                                  System.IO.Path.GetFileNameWithoutExtension(DimensionXmlFile)).Substring(
                                                  System.IO.Path.GetFileNameWithoutExtension(DimensionXmlFile).IndexOf(".") + 1),
                        Extension = ".dim",
                        FolderName = System.IO.Path.GetFileName(DimensionDir),
                        FolderPath = DimensionDir,
                        ObjectName = OLAPDimension.Name,
                        Type = SSASObject.ObjectType.Dimension,
                        XMLFileName = System.IO.Path.GetFileName(DimensionXmlFile),
                        XMLFilePath = DimensionXmlFile,
                        XmlModifiedDate = DimensionXmlFile == "" ? dt : System.IO.File.GetLastWriteTime(DimensionXmlFile),
                        FolderIncremetalID = System.IO.Path.GetFileNameWithoutExtension(DimensionDir).Substring(
                                             System.IO.Path.GetFileNameWithoutExtension(DimensionDir).IndexOf(".") + 1)
                    });
                }

                // Cube
                foreach (Cube OLAPCubex in OLAPDatabase.Cubes)
                {


                    idx++;
                    CubeID = idx;

                    string CubeDir = DbObjectsDir.Where(x => x.StartsWith(CurrentDbDir + "\\" + OLAPCubex.ID.ToString() + ".") && x.EndsWith(".cub")).DefaultIfEmpty("").First();
                    string CubeXmlFile = DbObjectsFiles.Where(x => x.StartsWith(CurrentDbDir + "\\" + OLAPCubex.ID.ToString() + ".") && x.EndsWith(".cub.xml")).DefaultIfEmpty("").First();

                    string[] CubeMeasureGroupsDir = System.IO.Directory.GetDirectories(CubeDir, "*", System.IO.SearchOption.TopDirectoryOnly);
                    string[] CubeMeasureGroupsFiles = System.IO.Directory.GetFiles(CubeDir, "*", System.IO.SearchOption.TopDirectoryOnly);


                    result.Add(new SSASObject
                    {
                        ID = idx,
                        ParentID = DbID,
                        ObjectID = OLAPCubex.ID,
                        FolderModifiedDate = CubeDir == "" ? dt : System.IO.Directory.GetLastWriteTime(CubeDir),
                        XmlIncremetalID = System.IO.Path.GetFileNameWithoutExtension(
                                                  System.IO.Path.GetFileNameWithoutExtension(CubeXmlFile)).Substring(
                                                  System.IO.Path.GetFileNameWithoutExtension(CubeXmlFile).IndexOf(".") + 1),
                        Extension = ".cub",
                        FolderName = System.IO.Path.GetFileName(CubeDir),
                        FolderPath = CubeDir,
                        ObjectName = OLAPCubex.Name,
                        Type = SSASObject.ObjectType.Cube,
                        XMLFileName = System.IO.Path.GetFileName(CubeXmlFile),
                        XMLFilePath = CubeXmlFile,
                        XmlModifiedDate = CubeXmlFile == "" ? dt : System.IO.File.GetLastWriteTime(CubeXmlFile),
                        FolderIncremetalID = System.IO.Path.GetFileNameWithoutExtension(CubeDir).Substring(
                                             System.IO.Path.GetFileNameWithoutExtension(CubeDir).IndexOf(".") + 1)
                    });

                    //Measure Group
                    foreach (MeasureGroup OLAPMeasureGroup in OLAPCubex.MeasureGroups)
                    {

                        idx++;
                        ObjectID = idx;
                        string MeasureGroupDir = CubeMeasureGroupsDir.Where(x => x.StartsWith(CubeDir + "\\" + OLAPMeasureGroup.ID.ToString() + ".") && x.EndsWith(".det")).DefaultIfEmpty("").First();
                        string MeasureGroupXmlFile = CubeMeasureGroupsFiles.Where(x => x.StartsWith(CubeDir + "\\" + OLAPMeasureGroup.ID.ToString() + ".") && x.EndsWith(".det.xml")).DefaultIfEmpty("").First();

                        string[] GroupPartitionDir = System.IO.Directory.GetDirectories(MeasureGroupDir, "*", System.IO.SearchOption.TopDirectoryOnly);
                        string[] GroupPartitionFiles = System.IO.Directory.GetFiles(MeasureGroupDir, "*", System.IO.SearchOption.TopDirectoryOnly);

                        result.Add(new SSASObject
                        {
                            ID = idx,
                            ParentID = CubeID,
                            ObjectID = OLAPMeasureGroup.ID,
                            FolderModifiedDate = MeasureGroupDir == "" ? dt : System.IO.Directory.GetLastWriteTime(MeasureGroupDir),
                            XmlIncremetalID = System.IO.Path.GetFileNameWithoutExtension(
                                                  System.IO.Path.GetFileNameWithoutExtension(MeasureGroupXmlFile)).Substring(
                                                  System.IO.Path.GetFileNameWithoutExtension(MeasureGroupXmlFile).IndexOf(".") + 1),
                            Extension = ".det",
                            FolderName = System.IO.Path.GetFileName(MeasureGroupDir),
                            FolderPath = MeasureGroupDir,
                            ObjectName = OLAPMeasureGroup.Name,
                            Type = SSASObject.ObjectType.MeasureGroup,
                            XMLFileName = System.IO.Path.GetFileName(MeasureGroupXmlFile),
                            XMLFilePath = MeasureGroupXmlFile,
                            XmlModifiedDate = MeasureGroupXmlFile == "" ? dt : System.IO.File.GetLastWriteTime(MeasureGroupXmlFile),
                            FolderIncremetalID = System.IO.Path.GetFileNameWithoutExtension(MeasureGroupDir).Substring(
                                                 System.IO.Path.GetFileNameWithoutExtension(MeasureGroupDir).IndexOf(".") + 1)
                        });

                        //Aggregations
                        foreach (AggregationDesign OLAPAggregationDesign in OLAPMeasureGroup.AggregationDesigns)
                        {

                            string AggregationDir = GroupPartitionDir.Where(x => x.StartsWith(MeasureGroupDir + "\\" + OLAPAggregationDesign.ID.ToString() + ".") && x.EndsWith(".agg")).DefaultIfEmpty("").First();
                            string AggregationXmlFile = GroupPartitionFiles.Where(x => x.StartsWith(MeasureGroupDir + "\\" + OLAPAggregationDesign.ID.ToString() + ".") && x.EndsWith(".agg.xml")).DefaultIfEmpty("").First();

                            idx++;

                            result.Add(new SSASObject
                            {
                                ID = idx,
                                ParentID = ObjectID,
                                ObjectID = OLAPAggregationDesign.ID,
                                FolderModifiedDate = AggregationDir == "" ? dt : System.IO.Directory.GetLastWriteTime(AggregationDir),
                                XmlIncremetalID = System.IO.Path.GetFileNameWithoutExtension(
                                                  System.IO.Path.GetFileNameWithoutExtension(AggregationXmlFile)).Substring(
                                                  System.IO.Path.GetFileNameWithoutExtension(AggregationXmlFile).IndexOf(".") + 1),
                                Extension = ".agg",
                                FolderName = System.IO.Path.GetFileName(AggregationDir),
                                FolderPath = AggregationDir,
                                ObjectName = OLAPAggregationDesign.Name,
                                Type = SSASObject.ObjectType.AggregationDesign,
                                XMLFileName = System.IO.Path.GetFileName(AggregationXmlFile),
                                XMLFilePath = AggregationXmlFile,
                                XmlModifiedDate = AggregationXmlFile == "" ? dt : System.IO.File.GetLastWriteTime(AggregationXmlFile),
                                FolderIncremetalID = System.IO.Path.GetFileNameWithoutExtension(AggregationDir).Substring(
                                                     System.IO.Path.GetFileNameWithoutExtension(AggregationDir).IndexOf(".") + 1)

                            });


                        }


                        //Partitions
                        foreach (Partition OLAPPartition in OLAPMeasureGroup.Partitions)
                        {

                            string PartitionDir = GroupPartitionDir.Where(x => x.StartsWith(MeasureGroupDir + "\\" + OLAPPartition.ID.ToString() + ".") && x.EndsWith(".prt")).DefaultIfEmpty("").First();
                            string PartitionXmlFile = GroupPartitionFiles.Where(x => x.StartsWith(MeasureGroupDir + "\\" + OLAPPartition.ID.ToString() + ".") && x.EndsWith(".prt.xml")).DefaultIfEmpty("").First();

                            idx++;

                            result.Add(new SSASObject
                            {
                                ID = idx,
                                ParentID = ObjectID,
                                ObjectID = OLAPPartition.ID,
                                FolderModifiedDate = PartitionDir == "" ? dt : System.IO.Directory.GetLastWriteTime(PartitionDir),
                                XmlIncremetalID = System.IO.Path.GetFileNameWithoutExtension(
                                                  System.IO.Path.GetFileNameWithoutExtension(PartitionXmlFile)).Substring(
                                                  System.IO.Path.GetFileNameWithoutExtension(PartitionXmlFile).IndexOf(".") + 1),
                                Extension = ".prt",
                                FolderName = System.IO.Path.GetFileName(PartitionDir),
                                FolderPath = PartitionDir,
                                ObjectName = OLAPPartition.Name,
                                Type = SSASObject.ObjectType.Partition,
                                XMLFileName = System.IO.Path.GetFileName(PartitionXmlFile),
                                XMLFilePath = PartitionXmlFile,
                                XmlModifiedDate = PartitionXmlFile == "" ? dt : System.IO.File.GetLastWriteTime(PartitionXmlFile),
                                FolderIncremetalID = System.IO.Path.GetFileNameWithoutExtension(PartitionDir).Substring(
                                                     System.IO.Path.GetFileNameWithoutExtension(PartitionDir).IndexOf(".") + 1)

                            });

                        }






                    }


                }

                //Mining Structure
                foreach (MiningStructure OLAPMiningStructure in OLAPDatabase.MiningStructures)
                {

                    idx++;

                    string MiningStructureDir = DbObjectsDir.Where(x => x.StartsWith(CurrentDbDir + "\\" + OLAPMiningStructure.ID.ToString() + ".") && x.EndsWith(".dms")).DefaultIfEmpty("").First();
                    string MiningStructureXmlFile = DbObjectsFiles.Where(x => x.StartsWith(CurrentDbDir + "\\" + OLAPMiningStructure.ID.ToString() + ".") && x.EndsWith(".dms.xml")).DefaultIfEmpty("").First();

                    result.Add(new SSASObject
                    {
                        ID = idx,
                        ParentID = DbID,
                        ObjectID = OLAPMiningStructure.ID,
                        FolderModifiedDate = MiningStructureDir == "" ? dt : System.IO.Directory.GetLastWriteTime(MiningStructureDir),
                        XmlIncremetalID = System.IO.Path.GetFileNameWithoutExtension(
                                          System.IO.Path.GetFileNameWithoutExtension(MiningStructureXmlFile)).Substring(
                                          System.IO.Path.GetFileNameWithoutExtension(MiningStructureXmlFile).IndexOf(".") + 1),
                        Extension = ".ds",
                        FolderName = System.IO.Path.GetFileName(MiningStructureDir),
                        FolderPath = MiningStructureDir,
                        ObjectName = OLAPMiningStructure.Name,
                        Type = SSASObject.ObjectType.MiningStructure,
                        XMLFileName = System.IO.Path.GetFileName(MiningStructureXmlFile),
                        XMLFilePath = MiningStructureXmlFile,
                        XmlModifiedDate = MiningStructureXmlFile == "" ? dt : System.IO.File.GetLastWriteTime(MiningStructureXmlFile),
                        FolderIncremetalID = System.IO.Path.GetFileNameWithoutExtension(MiningStructureDir).Substring(
                                             System.IO.Path.GetFileNameWithoutExtension(MiningStructureDir).IndexOf(".") + 1)

                    });
                }


                //Role
                foreach (Role OLAPRole in OLAPDatabase.Roles)
                {

                    idx++;

                    string RoleDir = DbObjectsDir.Where(x => x.StartsWith(CurrentDbDir + "\\" + OLAPRole.ID.ToString() + ".") && x.EndsWith(".dms")).DefaultIfEmpty("").First();
                    string RoleXmlFile = DbObjectsFiles.Where(x => x.StartsWith(CurrentDbDir + "\\" + OLAPRole.ID.ToString() + ".") && x.EndsWith(".dms.xml")).DefaultIfEmpty("").First();

                    result.Add(new SSASObject
                    {
                        ID = idx,
                        ParentID = DbID,
                        ObjectID = OLAPRole.ID,
                        FolderModifiedDate = RoleDir == "" ? dt : System.IO.Directory.GetLastWriteTime(RoleDir),
                        XmlIncremetalID = System.IO.Path.GetFileNameWithoutExtension(
                                          System.IO.Path.GetFileNameWithoutExtension(RoleXmlFile)).Substring(
                                          System.IO.Path.GetFileNameWithoutExtension(RoleXmlFile).IndexOf(".") + 1),
                        Extension = ".ds",
                        FolderName = System.IO.Path.GetFileName(RoleDir),
                        FolderPath = RoleDir,
                        ObjectName = OLAPRole.Name,
                        Type = SSASObject.ObjectType.Role,
                        XMLFileName = System.IO.Path.GetFileName(RoleXmlFile),
                        XMLFilePath = RoleXmlFile,
                        XmlModifiedDate = RoleXmlFile == "" ? dt : System.IO.File.GetLastWriteTime(RoleXmlFile),
                        FolderIncremetalID = System.IO.Path.GetFileNameWithoutExtension(RoleDir).Substring(
                                             System.IO.Path.GetFileNameWithoutExtension(RoleDir).IndexOf(".") + 1)

                    });

                }

            }



            return result;
        }
        catch (Exception ex)
        {
            return null;
        }
    }

}

GitHub 项目

我创建了一个小型 Windows 应用程序并将其上传到 GitHub,您可以将其作为单独的工具使用,或者您可以简单地复制到 Script Task 项目中的类并在脚本中使用它。

关于c# - 检索多维数据库对象目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55792689/

相关文章:

c# - 如何从其索引中获取组合框的值?

c# - SSIS如何强制祖父容器执行结果成功

sql-server - 如何取消处于已创建执行状态的 SSIS 作业

sql-server - ssis中如何将空白转换为null

c# - SlimDX 和 WPF 通过 D3DImage

c# - rdr 是一个 'variable' 但像 'method' 一样使用

sql-server - 将 GUID 连接到字符串 - Entity Framework 产生缓慢的查询

mysql - Excel 无法将 mysql 中的日期识别为日期

sql - 更新一行更快,还是删除它并插入新行更快?

sql-server - SSIS 从带有 Where 条件的 Excel 工作表中选择