Plz Try this...
using oASDatabase = Microsoft.AnalysisServices.Database;
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])
{
foreach(var role in asdb.Roles)
{
}
Microsoft.AnalysisServices.Role myNewRole = asdb.Roles.Add("myNewRole");
myNewRole.Members.Add(new Microsoft.AnalysisServices.RoleMember(""));
myNewRole.Update();
dbperm = asdb.DatabasePermissions.Add(myNewRole.ID);
dbperm.Read = Microsoft.AnalysisServices.ReadAccess.Allowed;
dbperm.Update();
foreach (oASCube ascube in asdb.Cubes)
{
cubeperm = ascube.CubePermissions.Add(myNewRole.ID);
cubeperm.Read = Microsoft.AnalysisServices.ReadAccess.Allowed;
cubeperm.Update();
}
}
ASServer.Disconnect();
}