Search code examples
c#.netssasamo

SSAS automation in c# - rename AAS attribute in c# pragmatically


I need help on SSAS automation in C#. I want to automate the rename the display name for the AAS attributes. To automate the full process of renaming using c#. please help on this. kindly share any links or article on this


Solution

  • The MS Documentation for AMO is here

    Add the AMO nuget packge to your Visual Studio project

    Then, you can connect to your SSAS Server from your code and change the dimension attribute.

    E.g.,

        private static void UpdateAttribute()
        {
            var serverName = ConfigurationManager.AppSettings["ServerName"];
            var databaseName = ConfigurationManager.AppSettings["DatabaseName"];
            var cubeName = ConfigurationManager.AppSettings["CubeName"];
            var dimensionName = ConfigurationManager.AppSettings["DimensionName"];
            var attributeName = ConfigurationManager.AppSettings["AttributeName"];
    
    
            //Server
            var server = new Server();
            server.Connect(serverName);
    
            //Database
            var db = server.Databases.FindByName(databaseName);
    
            //Cube
            var cube = db.Cubes.FindByName(cubeName);
    
            //dim
            var dim = db.Dimensions.FindByName(dimensionName);
    
            //attribute
            var attribute = dim.Attributes.FindByName(attributeName);
    
            var newAttributeName = $"{attribute.Name}_New";
    
            attribute.Name = newAttributeName;
    
            //this will update the dimension in the Server
            dim.Update();
    
    
        }
    

    Result

    The original attribute name was "Category" and now it is changed to "Category_New" in the Product dimension

    enter image description here