all groups > sql server reporting services > april 2005 >
You're in the

sql server reporting services

group:

Programmatically doing new role assignments



Programmatically doing new role assignments david.seruyange NO[at]SPAM gmail.com
4/11/2005 1:03:58 PM
sql server reporting services: Hello everyone -

A friend of mine is having some trouble using the browser based method
of assigning roles and I suggested that we do it programmatically just
in case errors were being suppressed by IE. So far I've seen a lot of
code that creates roles but none that assigns the role to a Windows
group. So for example, I've seen code that can build a role called FOO
with tasks A,B,C associated but how can I assign WINDOMAIN\Users to
that role?

Thanks much,

David Seruyange
Re: Programmatically doing new role assignments David Seruyange
4/12/2005 8:21:01 PM
Just in case anyone else runs into this, it is done with a policy
object - a short snippet of code like this will do the trick:

MyRS.ReportingService tmp = new MyRS.ReportingService();
// below the NetworkCredential class accepts 3 arguments:
// USERNAME, PASSWORD, DOMAIN
// this is to connect to ReportServer so use an admin account
tmp.Credentials = new NetworkCredential("myusername", "mypassword",
"MYDOMAIN");
try{
Role[] roles = tmp.ListRoles();
foreach(Role r in roles){
if(r.Name == "Browser"){
// modify 'r'
bool bInherit;
Policy[] polis = tmp.GetPolicies("/", out bInherit);
Policy[] pcopy = new Policy[polis.Length + 1];
Array.Copy(polis, pcopy, polis.Length);

Policy np = new Policy();
// MAKE THIS USERNAME CORRESPOND WITH A
// DOMAIN ACCOUNT
np.GroupUserName = @"DOMAIN\User";
np.Roles = new Role[]{r};

pcopy[pcopy.Length -1] = np;
// ASSIGN THIS to the FOLDER that contains
// your report off the ROOT "/"
tmp.SetPolicies("/REPORTFOLDER",pcopy);
Console.Write("Policy assignment has been made.");
}
}
}
catch(Exception ex){
Console.WriteLine(ex.ToString());
}
Re: Programmatically doing new role assignments Frank Matthiesen
4/13/2005 9:00:47 AM
[quoted text, click to view]


David,

look at bryan's blog under http://blogs.msdn.com/bryanke/articles/91726.aspx
You will find a really good example-script

regards

Frank

AddThis Social Bookmark Button