Re: System.Directoryservices getting TxIsolationLevel exeption?

From: Joe Kaplan \(MVP - ADSI\) (joseph.e.kaplan_at_removethis.accenture.com)
Date: 06/04/04


Date: Fri, 4 Jun 2004 12:51:33 -0500

Well, your error mentioned COM+ and transaction levels, so it looked like
you might be running this code inside of COM+/Enterprise Services. It seems
very unlikely that you would have done that on accident though as it
requires significant effort.

One general problem I see with your code is that you are catching the
exception that was thrown and rethrowing it with a more generic exception.
As a general rule, class library developers should never do this.
Essentially, you lose the context of the original exception including the
stack trace and add no value. If you ever do catch and rethrow, you should
just call throw without any arguments. This is covered in more detail in
the .NET Design Guidelines in MSDN. The only real reason to catch and
rethrow would be to add some debug or tracing information about the error
though.

The reason I bring this up is that it would be helpful to know what the type
is on the exception that gets thrown and what the stack trace is (you can
call ToString to print this out). Normally, adding a user to a group fails
because there are permissions issues, the user is already in the group, or
there is something about the object you are adding to the group that makes
it not valid to be a member of the group (this happens when you try to nest
the wrong types of groups for example).

Joe K.

"Robert Wallström" <s02image@student.informatik.gu.se> wrote in message
news:OXntqwkSEHA.3476@tk2msftngp13.phx.gbl...
> Hi Joe.. and thank you for your reply.
>
> In your answer you wondered if I could get my code to work outside of
COM+,
> I must admit that I dont really know what COM+ is/means and there for cant
> answer that question.
>
> Allthough when I test my code I test it in a consoleapplication project,
> with a an easy "static void main(string args[]) method. (code at the of
this
> message).
>
> I dont know if this makes any different but I am trying to add a user
> previously just created..(maybe there is some kind of restriction on doing
> so, if so is there a way around it?)
>
> I dont know if this led you closer to my problem, but any answer is
> appreciated..
>
> Thank you once again..
>
> //Below is another method from my AdManipulator class
> //supplymented as description to my consoleapplication test class
> public bool createUser(AdUser newUser)
>
> {
>
> try
>
> {
>
> /*the call below is executed whitout any execption and the user is added
>
> to the Active directory..no problem here (I hope;-))
>
> */
>
> DirectoryEntry user = addUserAccount(newUser);
>
> /*the call below is executed whitout any execption and the user's password
> is set
>
> ..no problem here (I hope;-))
>
> */
>
> setUserPassword(user, newUser.Password);
>
> /*the call below is executed whitout any execption and the user is enabled
>
> ..no problem here (I hope;-))
>
> */
>
> enableUser(user);
>
> if(newUser.Groups.Count > 0)
>
> {
>
> //the call below is the one that throws an exeption(look in previous post
> for method code)
>
> addUserToGroup(newUser);
>
> }
>
> }
>
> catch(Exception ex)
>
> {
>
> throw new Exception("Error creating user.\n" + ex.Message);
>
> }
>
> return true;
>
> }
>
>
>
> //Bellow is my Consoleapplication test class..
> class Class1
>
> {
>
> /// <summary>
>
> /// The main entry point for the application.
>
> /// </summary>
>
> [STAThread]
>
> static void Main(string[] args)
>
> {
>
> AdManipulator adm = new
AdManipulator("adminuser","password","domain.com");
>
> Console.Write("New user\nSupply new username:");
>
> AdUser user = new AdUser(Console.ReadLine());
>
> Console.Write("Supply password:");
>
> user.Password = Console.ReadLine();
>
> Console.Write("Supply group:");
>
> user.addGroup(Console.ReadLine());
>
> if(adm.createUser(user))
>
> {
>
> Console.WriteLine("Sucess!");
>
> }
>
> Console.ReadLine();
>
> }
>
> }
>
>
>
> "Joe Kaplan (MVP - ADSI)" <joseph.e.kaplan@removethis.accenture.com> skrev
i
> meddelandet news:OO6vzckSEHA.4068@TK2MSFTNGP09.phx.gbl...
> > It sounds like the error is related to COM+. Can you get the code to
work
> > outside of COM+ (in a console app for example)?
> >
> > Joe K.
> >
> > "Robert Wallström" <s02image@student.informatik.gu.se> wrote in message
> > news:O9wLKOiSEHA.2780@TK2MSFTNGP09.phx.gbl...
> > > Hi
> > > I am trying to add a user to a group in Active Directory using
> > > System.Directory
> > > Services
> > >
> > > But when I CommitChanges() I get the following exeption:
> > >
> > > (In swedish, I use a swedish version of XP-pro)
> > > "Egenskapen TxIsolationLevel för den COM+-komponent som skapas är
> starkare
> > > är TxIsolationLevel för transaktionens rotkomponent. Objektet kunde
inte
> > > skapas."
> > >
> > > Freely interpreted to English:
> > > "The property TxIsolationLevel for the COM+-component that is being
> > created
> > > is stronger than
> > > TxIsolationLevel for the transaktions rootcomponent. The object could
> not
> > be
> > > created."
> > >
> > > My code:
> > > public class AdManipulator
> > >
> > > {
> > >
> > > private DirectoryEntry root;
> > >
> > > private DirectorySearcher adSearcher;
> > >
> > > private string topDomain;
> > >
> > > private string domain;
> > >
> > > private string manipulatorName;
> > >
> > > private string manipulatorPass;
> > >
> > > private string path;
> > >
> > >
> > >
> > > public AdManipulator(string newManipulatorName, string
> > > newManipulatorPass,string newAdDomain)
> > >
> > > {
> > >
> > > topDomain = newAdDomain.Substring(newAdDomain.IndexOf(".") + 1);
> > >
> > > domain = newAdDomain.Substring(0,newAdDomain.IndexOf("."));
> > >
> > > path = "LDAP://DC=" + domain + ",DC=" + topDomain;
> > >
> > > manipulatorName = newManipulatorName;
> > >
> > > manipulatorPass = newManipulatorPass;
> > >
> > > root = new DirectoryEntry();
> > >
> > > root.Username = newManipulatorName;
> > >
> > > root.Password = newManipulatorPass;
> > >
> > > root.Path = path;
> > >
> > > root.AuthenticationType = AuthenticationTypes.Secure;
> > >
> > > adSearcher = new DirectorySearcher(root);
> > >
> > >
> > > }
> > >
> > > //Below is the method wich casts exeption...
> > >
> > > public bool addUserToGroup(AdUser user)
> > >
> > > {
> > >
> > > try
> > >
> > > {
> > >
> > > adSearcher.Filter = "(sAMAccountName=" + user.Username + ")";
> > >
> > > SearchResult res = adSearcher.FindOne();
> > >
> > > if(res == null)
> > >
> > > {
> > >
> > > throw new Exception("Error no such user!\n");
> > >
> > > }
> > >
> > > DirectoryEntry deUser = new DirectoryEntry(res.Path);
> > >
> > > foreach(string st in user.Groups)
> > >
> > > {
> > >
> > > adSearcher.Filter = "(CN=" + st + ")";
> > >
> > > res = adSearcher.FindOne();
> > >
> > > if(res != null)
> > >
> > > {
> > >
> > > DirectoryEntry group = new DirectoryEntry(res.Path);
> > >
> > >
> >
>
group.Properties["member"].Add(deUser.Properties["distinguishedName"].Value)
> > > ;
> > >
> > > group.CommitChanges();//on executing this row I get an exeption...
> > >
> > > }
> > >
> > > }
> > >
> > > }
> > >
> > > catch(Exception ex)
> > >
> > > {
> > >
> > > throw new Exception("Error adding user to group.\n" + ex.Message);
> > >
> > > }
> > >
> > > return true;
> > >
> > >
> > > }
> > >
> > > }
> > >
> > > //Bellow is the classhead for the AdUser object this is just a
> > >
> > > //object wich carries data about a specific user..
> > >
> > > //this object is used in addUserToGroup(AdUser user)
> > >
> > > public class AdUser
> > >
> > > {
> > >
> > >
> > > //Common user variables, more could be used..
> > >
> > > private string username;
> > >
> > > private string password;
> > >
> > > private string givenname;
> > >
> > > private string initials;
> > >
> > > private string surname;
> > >
> > > private string displayname;
> > >
> > > private string discription;
> > >
> > > private string telephoneNumber;
> > >
> > > private string mail;
> > >
> > > private string url;
> > >
> > > private StringCollection groups = new StringCollection();
> > >
> > > }
> > >
> > >
> > >
> > > Have anyone got an similar exeption?
> > >
> > > Or might anyone se what Im doing wrong in my code..
> > >
> > > Thank you...
> > >
> > >
> >
> >
>
>



Relevant Pages

  • Re: test if a string is a valid number?
    ... exception type so I could issue a meaningful error message. ... superclass exception, e.g., CLexicalException, then I can derive ... MVP Tips: http://www.flounder.com/mvp_tips.htm ...
    (microsoft.public.vc.mfc)
  • Re: Vector and derived classes objects
    ... > wont be called for the objects the pointer points to, hence I dont see ... > any way an exception can be thrown there with my push_back. ... Josuttis as also mentiones that in his STL book. ...
    (comp.lang.cpp)
  • Re: An unsupported operation was attempted @ ProcessShellCommand
    ... Thank you Joe. ... had a ddxcontol function for it. ... exception, but if I remove that function as a test, the same exception ... I did nothing tricky vis a vis any internal MFC ...
    (microsoft.public.vc.mfc)
  • Re: exception handling in complex Python programs
    ... The only ones -really- worth catching are those you can recover from. ... You're still throwing an exception, ... If you can derive recoverable information, then why rethrow? ...
    (comp.lang.python)
  • Re: Monte Carlo computer go methods
    ... When I hear of these rapid advancements, ... mostly what every book says: lots of study, trying to play the moves they learn even if they dont understand them, reading, counting liberties, never play a move which one has been told is bad *until* they are sure this is an exception, etc. ...
    (rec.games.go)