Thursday, March 29, 2012

EnumObjectPermissions on a ApplicationRole and DatabaseRole objects returns o entries

HI,

Call to EnumObjectPermissions method on a SMO ApplicationRole or DatabseRole object returns an empty collection, however, a call to EnumDatabaseRoleMember on a DatabaseRole object using DMO returns the correct list of membership. Please clarify.

Regards,

Joginder

Hmm I had the same problem with SMO, but I did not try DMO.

I found a workaround. Use the similar method at the Database level, and supply the role name as a string.

using Microsoft.SqlServer.Management.Smo;

using Microsoft.SqlServer.Management.Common;

Database dbHold = smoServer.Databases["YourDB"];

String holdString;

foreach( DatabaseRole dr in dbHold.Roles)

{

ObjectPermissionInfo[] ra = dr.EnumObjectPermissions(); // mysteriously returns null!!

foreach (ObjectPermissionInfo opi in dbHold.EnumObjectPermissions(dr.Name))

{

holdString = String.Format("-OPIRole:{0} has {1}{2}{3}", dr.Name, opi.Grantor, opi.Grantee, opi.ObjectName);

}

}

}

Regards,

Chip

No comments:

Post a Comment