locked
PartitionCollection.Add() method doesn't seem to do what you'd think RRS feed

  • Question

  •  

    Hi,

    I am using AMO to add a new partition to an existing measure group but unfortunately its not working. I'm cloning an existing partition and then adding it to the partitions collection like so (slightly altered for brevity):

     

    Code Snippet
        Function CreatePartition(ByRef mg As MeasureGroup) As Boolean
            Dim partition As Partition
            partition = mg.Partitions(0).Clone()
            partition.ID = partition.ID + "_new"
            partition.Name = partition.ID
            mg.Partitions.Add(partition)
        End Function

     

     

    The code runs fine and if I step through the code I can interrogate the MeasureGroup afterwards and see that the partitions collection has 1 more partition in it than it did before.

     

    However, when I look at the mesaure group within SSMS I don't see the new partition.


    So, simple question, what am I doing wrong? Do I need to do anything more to make my new partition show up?

     

    Thanks

    jamie

     

    P.S. Here is the full code, which I am executing from SSIS:

     

     

    Code Snippet

    Imports System
    Imports System.Data
    Imports System.Math
    Imports Microsoft.SqlServer.Dts.Runtime
    Imports Microsoft.AnalysisServices

    Public Class ScriptMain

        Public Sub Main()

            Dim server As New Server
            Dim cube As Cube
            Dim mg As MeasureGroup
            Dim weekNum As Int32
            Dim vars As Variables
            Try
                'Get week number
                Dts.VariableDispenser.LockOneForRead("User::WeekSequenceNum", vars)
                weekNum = Convert.ToInt32(vars("User::WeekSequenceNum").Value)

                server.Connect(Dts.Connections("olap").ConnectionString)
                cube = server.Databases("BiB").Cubes("iQube")

                For Each mg In cube.MeasureGroups
                    If (Not PartitionExists(mg, weekNum)) Then
                        CreatePartition(mg, weekNum)
                    End If
                Next
            Catch ex As Exception
                Dts.Events.FireError(-1, "Partition Creator", ex.Message, "", 0)
            End Try

            Dts.TaskResult = Dts.Results.Success
        End Sub

     

        Function CreatePartition(ByRef mg As MeasureGroup, ByVal weekNum As Int32) As Boolean
            Dim partitionName As String
            Dim partition As Partition
            partition = mg.Partitions(0).Clone()
            partition.ID = partition.ID + "_" + Right("000" + weekNum.ToString(), 4)
            partition.Name = partition.ID
            mg.Partitions.Add(partition)
        End Function

     

        Function PartitionExists(ByVal mg As MeasureGroup, ByVal weekNum As Int32) As Boolean
            Dim returnVal As Boolean
            Dim partition As Partition
            Dim expectedPartitionName As String

            returnVal = False
            expectedPartitionName = mg.Name + "_" + Right("000" + weekNum.ToString(), 4)
            For Each partition In mg.Partitions
                If partition.Name = expectedPartitionName Then
                    returnVal = True
                End If
            Next

            Return returnVal
        End Function
    End Class

     

     

     

     

    Friday, August 29, 2008 2:20 PM

Answers

  • For update :

     

    mg.Update(UpdateOption.ExpandFull)

     

    cube.Update(UpdateOption.ExpandFull)

     

    Let me know if it doesnot work.

     

    Regards..
    Girija Shankar

     

    Friday, August 29, 2008 3:03 PM
    Answerer

All replies

  • Hi,

     

    I think you need to do the MeasureGroup.Update() or Cube.Update(). You have created the partition added that to the collection but not committed to database.

     

    Hope this helps..

     

    Regards ..

    Girija Shankar

    Friday, August 29, 2008 3:02 PM
    Answerer
  • For update :

     

    mg.Update(UpdateOption.ExpandFull)

     

    cube.Update(UpdateOption.ExpandFull)

     

    Let me know if it doesnot work.

     

    Regards..
    Girija Shankar

     

    Friday, August 29, 2008 3:03 PM
    Answerer
  •  Girija Shankar wrote:

    For update :

     

    mg.Update(UpdateOption.ExpandFull)

     

    cube.Update(UpdateOption.ExpandFull)

     

    Let me know if it doesnot work.

     

    Regards..
    Girija Shankar

     

     

    YEEEESSSSS!! Girija...THANKYOU!!!

     

    mg.Update(UpdateOptions.ExpandFull) did the trick.

     

    brilliant. Superb. Etc....

     

    -Jamie

    Friday, August 29, 2008 3:13 PM