Click here to Skip to main content
15,894,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear All,

In order to create a new SSAS OLAP role from an all ebracing one just copying than removing superfluos cubes from the new one will do.

The problem is to automate the process:
1. Extract list of OLAP cubes pertinent to a specyfic role, prior to highlight them
THAN
2. to remove the highlighted ones


I have found something pretty old that is merely stub - dimension list . Do you have more complete solution?


Thank you in advance
LP

What I have tried:

<pre>excerpted from book "A Programmer's Guide to ADO.NET in C#".


Accessing OLAP Server Data with ADO .NET[^]

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

Programming AMO security objects - BI | Microsoft Docs[^]
Posted
Updated 29-Jan-19 21:28pm

1 solution

Plz Try this...

using oASDatabase = Microsoft.AnalysisServices.Database;//add reference C:\Program Files (x86)\Microsoft SQL Server\110\SDK\Assemblies\Microsoft.AnalysisServices.DLL
using oASCube = Microsoft.AnalysisServices.Cube;


string ASConnectionString = "Data Source=localhost;Initial Catalog=doesntmatter;Provider=MSOLAP.5;Integrated Security=SSPI;Impersonation Level=Impersonate;";
string DatabaseName= "yourcubeCatalogName"
 Microsoft.AnalysisServices.DatabasePermission dbperm; 
Microsoft.AnalysisServices.CubePermission cubeperm; 
using(var ASServer= new Microsoft.AnalysisServices.Server())
{
    ASServer.Connect(ASConnectionString);
    
    using (oASDatabase asdb = ASServer.Databases[DatabaseName]) //Or do foreach like foreach (oASDatabase asdb in ASServer.Databases)
    {
        //get existing roles or search the role you want
        foreach(var role in asdb.Roles)
        {
            //do your stuff
        }
        //create new role

        Microsoft.AnalysisServices.Role myNewRole = asdb.Roles.Add("myNewRole");
        myNewRole.Members.Add(new Microsoft.AnalysisServices.RoleMember("")); // e.g. domain\\user  
        myNewRole.Update();
        dbperm = asdb.DatabasePermissions.Add(myNewRole.ID);
        dbperm.Read = Microsoft.AnalysisServices.ReadAccess.Allowed;
        dbperm.Update();

        //add the role to all cubes in the catalog or assigned specific cube oASCube ascube = asdb.Cubes["MyCubeName"] 
        foreach (oASCube ascube in asdb.Cubes)
        {
            cubeperm = ascube.CubePermissions.Add(myNewRole.ID);
            cubeperm.Read = Microsoft.AnalysisServices.ReadAccess.Allowed;
            //cubeperm.Write = Microsoft.AnalysisServices.WriteAccess.Allowed; 
            cubeperm.Update(); 
        } 
    }

   ASServer.Disconnect();
 }
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900