locked
Drop and Create role in Analysis Services Tabular with C# RRS feed

  • Question

  • Hello,

       I have an Analysis Services Tabular compatibility 1200 (dll : Microsoft.AnalysisServices.Tabular). Can u help me to know how i can add and drop role please?.

    For Now I can drope a member of a role but not the role. I try to use the function ModelPermission without sucess.

    Can someone help me pease.

    Regards


    Reponse

    Wednesday, October 24, 2018 8:44 AM

Answers

  • If you are using the current release of the AMO / TOM libraries then the following example will create a basic role and then remove it.

    using Microsoft.AnalysisServices.Tabular;
    
    namespace ConsoleAppAmo
    {
        class Program
        {
            static void Main(string[] args)
            {
                CreateRole();
                RemoveRole();
            }
    
            public static void CreateRole()
            {
    
                var svr = new Server();
                svr.Connect("localhost\\tab17");
                var db = svr.Databases["Adventure Works"];
                var model = db.Model;
    
                ModelRole newRole = new ModelRole
                {
                    Name = "TestRole"
                };
                WindowsModelRoleMember roleMember = new WindowsModelRoleMember
                {
                    MemberName = "domain\\username"
                };
                newRole.Members.Add(roleMember);
                newRole.ModelPermission = ModelPermission.Read;
                model.Roles.Add(newRole);
    
                model.SaveChanges();
                svr.Disconnect();
            }
    
            public static void RemoveRole()
            {
                var svr = new Server();
                svr.Connect("localhost\\tab17");
                var db = svr.Databases["Adventure Works"];
                var model = db.Model;
                model.Roles.Remove("TestRole");
                model.SaveChanges();
                svr.Disconnect();
            }
    
    
        }
    }
    


    http://darren.gosbell.com - please mark correct answers

    • Marked as answer by Adghar Wednesday, October 24, 2018 4:18 PM
    Wednesday, October 24, 2018 11:41 AM