元数据管理器中的错误。由'yyy'多维数据集引用的ID为'xxx'的维度不存在

时间:2013-11-05 19:41:47

标签: c# ssas olap-cube

我在创建维度属性时遇到错误我希望附加更多属性,但它会给出异常。

#region创建创建维度,属性,层次结构和成员属性对象。         ///创建维度,属性,层次结构和成员属性对象。

    private static object[] CreateDimension(Database objDatabase, DataSourceView objDataSourceView, string[,] strTableNamesAndKeys, int intDimensionTableCount)
    {
        try
        {
            Console.WriteLine("Creating the Dimension, Attribute, Hierarchy, and MemberProperty Objects ...");


            Dimension[] objDimensions = new Dimension[intDimensionTableCount];
            for (int i = 0; i < intDimensionTableCount; i++)
            {
                objDimensions[i] = (Dimension)GenerateDimension(objDatabase, objDataSourceView, strTableNamesAndKeys[i, 0], strTableNamesAndKeys[i, 1]);
            }


            return objDimensions;
        }
        catch (Exception ex)
        {
            Console.WriteLine("Error in Creating the Dimension, Attribute, Hierarchy, and MemberProperty Objects. Error Message -> " + ex.Message);
            return null;
        }
    }
    /// Generate single dimension.

    static DataItem CreateDataItem(DataSourceView dsv, string tableName, string columnName)
    {
        DataTable dataTable = ((DataSourceView)dsv).Schema.Tables[tableName];
        DataColumn dataColumn = dataTable.Columns[columnName];
        return new DataItem(tableName, columnName,
            OleDbTypeConverter.GetRestrictedOleDbType(dataColumn.DataType));
    }
    private static object GenerateDimension(Database objDatabase, DataSourceView objDataSourceView, string strTableName, string strTableKeyName)
    {
        try
        {
            Dimension objDimension = new Dimension();

            //Add Dimension to the Database
            objDimension = objDatabase.Dimensions.Add(strTableName);
            objDimension.Source = new DataSourceViewBinding(objDataSourceView.ID);
            DimensionAttributeCollection objDimensionAttributesColl = objDimension.Attributes;
            //Add Dimension Attributes
            DimensionAttribute objAttribute = objDimensionAttributesColl.Add(strTableKeyName);
            //Set Attribute usage and source
            objAttribute.Usage = AttributeUsage.Key;
            objAttribute.KeyColumns.Add(strTableName, strTableKeyName, OleDbType.Integer);

            objDimension.Update();

            if (strTableName == "DimProduct")
            {
          //  objDimension = objDatabase.Dimensions.Add(strTableName);
                Dimension dim;
                DimensionAttribute attr;

                dim = objDatabase.Dimensions.GetByName("DimProduct");
                attr = dim.Attributes.Add("Weight");
                attr.KeyColumns.Add(CreateDataItem(objDatabase.DataSourceViews[0], "DimProduct", "Weight"));
                attr.AttributeHierarchyEnabled = false;

                objDatabase.Update();

            }
            return objDimension;
        }
        catch (Exception ex)
        {
            Console.WriteLine("Error in Creating the Dimension, Attribute, Hierarchy, and MemberProperty Objects - GenerateDimension. Error Message -> " + ex.Message);
            return null;
        }
    }
    #endregion Creating a Creating the Dimension, Attribute, Hierarchy, and MemberProperty Objects.

我该怎么办?

0 个答案:

没有答案