Error Creating MeausreGroups and Creating Cube using AMO

Hello,

I am using AMO to dynamically create cubes in our Analysis Services Database. When I run my code below, I kept receving the error message says that the cube has no measure group. The error was raised when the execution reaches the cube.update line. However, as indicated in the code, the measure group was just added before the cube is updated. I am wondering if there is any property that I should set in the code to correct this. I've looked throught the sample AMO application that's included with the SQL 2005 installation, and couldn't find any hint. I also tried to use code to insert a cube that's a clone of another one, which successed, that means I do have the proper permission to add a new cube to the database.

I've included my code below... any help from any one would be greatly appreciated.

Thank you VERY MUCH.

Hsiao-I

---------------------------------------------------------------------------------------------------

Dim newClientCube As Cube = DB.Cubes.FindByName(Me.strClientName.ToLower())

If (NOT newClientCube IS NOTHING) Then

newClientCube.Drop()

End If

'| ------------------------------------------------

'| Create Cube

'| ------------------------------------------------

newClientCube = DB.Cubes.Add(Me.strClientName)

newClientCube.Name = Me.strClientName.ToLower()

newClientCube.Source = New DataSourceViewBinding(DB.DataSourceViews.GetByName(Me.strDSVName).ID)

Dim errConfig As New ErrorConfiguration

errConfig.KeyErrorAction = KeyErrorAction.DiscardRecord

errConfig.KeyNotFound = ErrorOption.IgnoreError

newClientCube.ErrorConfiguration = errConfig

'| ------------------------------------------------

'| Create Cube Dimentions

'| ------------------------------------------------

Dim _dim As Dimension

_dim = DB.Dimensions.GetByName(Me.strClientName & "_ClipType")

newClientCube.Dimensions.Add(_dim.ID, "ClipType", "ClipType")

Dim dsv As DataSourceView = DB.DataSourceViews.FindByName(Me.strDSVName)

Dim coverageMeasureGroup As MeasureGroup = _

newClientCube.MeasureGroups.FindByName("Coverage")

If (NOT coverageMeasureGroup IS NOTHING) Then

coverageMeasureGroup.Drop()

End If

coverageMeasureGroup = newClientCube.MeasureGroups.Add("Coverage")

coverageMeasureGroup.StorageMode = StorageMode.Molap

coverageMeasureGroup.ProcessingMode = ProcessingMode.LazyAggregations

coverageMeasureGroup.Type = MeasureGroupType.Regular

'| ------------------------------------------------

'| Add Measure to the group.

'| ------------------------------------------------

Dim strCoverageFactTable As String = "vw_" & strClientName & "coverage_single"

'| Count

MS = coverageMeasureGroup.Measures.Add("Clip Count")

MS.AggregateFunction = AggregationFunction.Count

MS.DataType = MeasureDataType.Inherited

MS.Source = CreateDataItem(dsv, strCoverageFactTable, "Coverage_Number_of_Clips")

'| ------------------------------------------------

'| Connects the PublicationDate Dimension to the Coverage Measure Group

'| ------------------------------------------------

Dim cubeDim As CubeDimension

Dim regMeasureDimension As RegularMeasureGroupDimension

Dim attrMeasureGroup As MeasureGroupAttribute

'| ------------------------------------------------

'| Connects the ClipType Dimension to the Coverage Measure Group

'| ------------------------------------------------

cubeDim = newClientCube.Dimensions.GetByName("ClipType")

regMeasureDimension = new RegularMeasureGroupDimension(cubeDim.ID)

coverageMeasureGroup.Dimensions.Add (regMeasureDimension)

attrMeasureGroup = _

regMeasureDimension.Attributes.Add(cubeDim.Dimension.Attributes.GetByName("Clip_Type_ID").ID)

attrMeasureGroup.Type = MeasureGroupAttributeType.Granularity

attrMeasureGroup.KeyColumns.Add(CreateDataItem(DB.DataSourceViews.GetByName(Me.strDSVName), _

strCoverageFactTable, _

Me.strClientName & "cliptype"))

'| --------------------------------------------------------------

'| Create Partition for data storing

'| --------------------------------------------------------------

If (coverageMeasureGroup.Partitions.FindByName("coverage") IS NOTHING) THEN

Dim part As Partition

part = coverageMeasureGroup.Partitions.Add("coverage")

part.StorageMode = StorageMode.Molap

part.Source = new QueryBinding(dsv.ID, _

"SELECT * FROM [dbo].[vw_kinkoscoverage_single]")

End If

newClientCube.Update () ' <-- Error Happens Here!!!!



Answer this question

Error Creating MeausreGroups and Creating Cube using AMO

  • Error Creating MeausreGroups and Creating Cube using AMO