How to get the currentmember by using C#


  •  When I run the following MDX to get the currentmember of [Time-UTC], i got the error like following :

    select {[Measures].[GetCubeName]} on 0
    from metl
    where [Time - UTC].[Fiscal].[Year].&[2012]

    #Error Stored procedures errors: The CurrentCube property on the Context object cannot be used since there is no available cube context. This typically occurs because the stored procedure is not being called within an MDX/SQL query to a cube. Execution of the managed stored procedure getCurrentCubeAttribute failed with the following error: Exception has been thrown by the target of an invocation..

    Here is the backend code:(The hierarchy name is correct, i can get the correct result if i use the second line.)

    Microsoft.AnalysisServices.AdomdServer.CubeDef cube = Microsoft.AnalysisServices.AdomdServer.Context.CurrentCube;
    //return cube.Dimensions["Time - UTC"].Hierarchies["Fiscal"].Name;
    return cube.Dimensions["Time - UTC"].Hierarchies["Fiscal"].CurrentMember.Name;

    Thursday, June 07, 2012 2:23 PM