ORA-31201: DBMS_LDAP: generic error: Invalid BER ELEMENT
Hello world,
This post is dedicated to this error which calls for “Please report the error number and description to Oracle Support”.
The most likely cause is that you are using the “dbms_ldap” code samples for oracle and after you perform a search on active directory that returns no results you try to free a null element using “DBMS_LDAP.ber_free(my_ber_elmt, 0);”
To get rid of the error replace the above statement with this one:
if (my_ber_elmt is not null) then
DBMS_LDAP.ber_free(my_ber_elmt, 0);
end if;
What’s strange about this error it lists as cause: “There has been an error in the DBMS_LDAP package” and proposes as action “Please report the error number and description to Oracle Support”.
My guess is that the oracle programmers also forgot to do a null check and they tried to free a null element inside DBMS_LDAP.ber_free instead of checking for this case and throwing a custom exception.
Well, nobody’s perfect. I’m nobody :)

OMG!!!! That’s *IT*. Sheesh. Thanks a bunch for this tip, I’ve been fighting with DBMS_LDAP for quite some time.
Chris Yoder
May 29, 2009 at 9:11 pm
Exactly the information I needed – Thanks for taking the time to post it!
Bryan Fowler
July 17, 2009 at 2:31 pm
In 1 minute you solved weeks of headache! Thanks a lot!
Gabor Revesz
February 28, 2011 at 10:28 pm