Friday, February 24, 2012

AMO Role drop trouble

I've some trouble trying to drop roles with AMO and the following code:


Role oCurrentRole = oOLAPDB.Roles.GetByName(<role name>);
oCurrentRole.Drop(DropOptions.AlterOrDeleteDependents);

Most of the time it's OK but I've sometimes this error

Exception non gre : System.InvalidOperationException: Impossible de supprimer l'objet ? Role ?my role , il doit faire partie d'un objet Server connect.
à Microsoft.AnalysisServices.MajorObject.DropPrivate(DropOptions options, XmlaWarningCollection warnings, ImpactDetailCollection impactResult, Boolean analyzeImpactOnly)
à Microsoft.AnalysisServices.MajorObject.Drop(DropOptions options)

(in english: Unhandled exception : System.InvalidOperationException: Unable to drop ? Role object ?my role , it must be part of a connected Server object)

I'm the only one connected to this server and I'm sure this role isn't used.

One thing to mention: It seems I've this error only with roles with members which are no more existing in the domain (they were when the role was created but get deleted later).

Any idea ? How could I drop these roles with AMO ?

David,

I created an account on my local system, JunkUser, and then created a role in Adventure Works DW called JunkRole. JunkUser is the lone member of this role. I then dropped the JunkUser account from my system.

In SSIS, I created a package with a single Script task. I added the AMO reference and an Imports statement to simplify my code. In Sub Main, I added this code:

Code Snippet

Dim MyServer As New Server

MyServer.Connect(".")

Dim MyDatabase As Database = MyServer.Databases.GetByName("Adventure Works DW")

Dim MyRole As Role = MyDatabase.Roles.GetByName("JunkRole")

MyRole.Drop(DropOptions.AlterOrDeleteDependents)

MyServer.Disconnect()

I executed the SSIS package. It completed successsfully and I verified the JunkRole had been dropped.

I am running on SP2.

Not sure what might else may be causing the problem you are seeing.

B.

|||My bad Sad

You're right Bryan, it doens't matter if the user has been deleted or not

In fact, I had a nice
oServer.Disconnect();
just before my code... And of course, oServer is my OLAP Server object... Now that I'm thinking about it, the error message was quite explicit ("...connected Server") Sad

No comments:

Post a Comment