Delen via


ADAM running on Windows 2003 Gives exception 0x8007200a while updating null attributes

Recently, I was working on a scenario where I was trying to update the attributes of ADAM objects. If I clear an attribute value which is null and then I call CommitChanges on the object, it gives me an exception :

0x8007200a (The specified directory service attribute or value does not exist)

Here is the code sample which I was trying:

DirectoryEntry de = new DirectoryEntry("LDAP://localhost:50002/CN=TestUser,CN=Roles,CN=Partition1,DC=MyWorld,DC=COM");    
de.Properties["otherHomePhone"].Clear();           
de.Properties["otherHomePhone"].Add("12345");
de.CommitChanges();

After doing some research on it, I found that this behavior is seen because ADSI doesn’t send the control LDAP_SERVER_PERMISSIVE_MODIFY_OID [ msdn.microsoft.com/en-us/library/aa366984(VS.85).aspx ] for ADAM or any third party LDAP servers. This control modifies the default behavior of ldap_modify_ext function which by default doesn’t allow the deletion of an attribute value that is not set.

So If you do not want to fall into this scenario, just check for the null before calling CommitChanges on the object.

DirectoryEntry de = new DirectoryEntry("LDAP://localhost:50002/CN=TestUser,CN=Roles,CN=Partition1,DC=MyWorld,DC=COM");
if (de.Properties["otherHomePhone"].Count > 0)
{
   de.Properties["otherHomePhone"].Clear();
}
de.Properties["otherHomePhone"].Add("12345");
de.CommitChanges();

ADAM running on Windows 7/ Vista/ 2008 or 2008 R2 does not exhibit this behavior. However, the workaround will function against all instances of ADAM running on any windows operating system.