"There is no such object on the server" Error after Active Directory SetPasword call
-
Hello I use this code to create users in active directory, and set their passwords:
static void Main(string[] args) { DirectoryEntry parent = new DirectoryEntry("LDAP://test/OU=Admins,DC=test,DC=org"); Console.WriteLine("OU: "+parent.Name); Console.WriteLine("Domain name:" + System.DirectoryServices.ActiveDirectory.Domain.GetCurrentDomain().Name); string test = "testuser"; for (int i = 0; i < 20; i++) { try { DirectoryEntry child = parent.Children.Add("CN=" + test + i.ToString(), "User"); Console.WriteLine(test + i.ToString() + ": create object"); child.Properties["name"].Value = test + i.ToString(); child.Properties["displayName"].Value = test + i.ToString(); //child.Properties["userPrincipalName"].Value = test + i.ToString() + "@" + System.DirectoryServices.ActiveDirectory.Domain.GetCurrentDomain().Name; child.Properties["GivenName"].Value = test + i.ToString(); child.Properties["Initials"].Value = "q"; child.Properties["sn"].Value = test + i.ToString(); child.Properties["sAMAccountName"].Value = test + i.ToString(); child.CommitChanges(); Console.WriteLine(test + i.ToString() + ": commit info"); child.Invoke("SetPassword", new object[] { "!qwe@ASD" }); child.CommitChanges(); Console.WriteLine(test + i.ToString() + ": commit passowrd"); } catch (Exception ex) { Console.WriteLine(test + i.ToString() + ":"+ ex.ToString()); } } }
Within the loop, some users are created and their passwords set successfully, and randomly setting password for some users fail with this error: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.DirectoryServices.DirectoryServicesCOMException (0x80072030): There is no such object on the server. (Exception from HRESULT: 0x80072030) --- End of inner exception stack trace --- at System.DirectoryServices.DirectoryEntry.Invoke(String methodName, Object[] args) What are the possible causes for this error? and what are the workarounds?Hesham A. Amin My blog
-
Hello I use this code to create users in active directory, and set their passwords:
static void Main(string[] args) { DirectoryEntry parent = new DirectoryEntry("LDAP://test/OU=Admins,DC=test,DC=org"); Console.WriteLine("OU: "+parent.Name); Console.WriteLine("Domain name:" + System.DirectoryServices.ActiveDirectory.Domain.GetCurrentDomain().Name); string test = "testuser"; for (int i = 0; i < 20; i++) { try { DirectoryEntry child = parent.Children.Add("CN=" + test + i.ToString(), "User"); Console.WriteLine(test + i.ToString() + ": create object"); child.Properties["name"].Value = test + i.ToString(); child.Properties["displayName"].Value = test + i.ToString(); //child.Properties["userPrincipalName"].Value = test + i.ToString() + "@" + System.DirectoryServices.ActiveDirectory.Domain.GetCurrentDomain().Name; child.Properties["GivenName"].Value = test + i.ToString(); child.Properties["Initials"].Value = "q"; child.Properties["sn"].Value = test + i.ToString(); child.Properties["sAMAccountName"].Value = test + i.ToString(); child.CommitChanges(); Console.WriteLine(test + i.ToString() + ": commit info"); child.Invoke("SetPassword", new object[] { "!qwe@ASD" }); child.CommitChanges(); Console.WriteLine(test + i.ToString() + ": commit passowrd"); } catch (Exception ex) { Console.WriteLine(test + i.ToString() + ":"+ ex.ToString()); } } }
Within the loop, some users are created and their passwords set successfully, and randomly setting password for some users fail with this error: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.DirectoryServices.DirectoryServicesCOMException (0x80072030): There is no such object on the server. (Exception from HRESULT: 0x80072030) --- End of inner exception stack trace --- at System.DirectoryServices.DirectoryEntry.Invoke(String methodName, Object[] args) What are the possible causes for this error? and what are the workarounds?Hesham A. Amin My blog
-
We have solved the issue long time ago, so I don't remember the issue accurately. But as I remember, it was related to replication. There were multiple domain controllers serving the domain. If first
CommitChanges
saves data to dc1, the second may go to dc2. The solution is to add users in batch and replicate the domain controllers then update the password in another cycle.Hesham A. Amin My blog twitter: @HeshamAmin