title: Oracle & Active Directory : A love/hate relationship
body: <p>I'm currently trying to access Active Directory via the dbms_ldap API in Pl/Sql (Oracle). The trouble is that I'm not able to connect with my own username and password or anynoymously.</p>
  
  <p>However, in C# I can connect anonymously with this code :</p>
  
  <pre><code>DirectoryEntry ldap = new DirectoryEntry("LDAP://Hostname");
  DirectorySearcher searcher = new DirectorySearcher(ldap);
  searcher.Filter = "(SAMAccountName=username)";
  SearchResult result = searcher.FindOne();
  </code></pre>
  
  <p>If I try to connect anonymously in Oracle, I only get the error(ORA-31202 : LDAP client/server error) when I try to search (and the result code for the bind is SUCCESS)...</p>
  
  <pre><code>my_session := dbms_ldap.init('HOST','389');
  retval := dbms_ldap.simple_bind_s(my_session, '', '');
  retval := dbms_ldap.search_s(my_session, ldap_base,  dbms_ldap.scope_subtree, 'objectclass=*', my_attrs, 0, my_message);
  </code></pre>
  
  <p>Why is the anonymous connection is C# works but doesn't work in Pl/Sql? Do you have any other idea to connect to Active Directory via Oracle?</p>
  
  <p>Help me reunite them together.
  <br/> Thanks.</p>
  
  <p><strong>Edit 1</strong><br>
  When I bind with anonymous credentials I get : <br></p>
  
  <blockquote>
    <p>ORA-31202: DBMS_LDAP: LDAP client/server error<br>
    00000000: LdapErr: DSID-0C090627, 
    comment: In order to perform this operation a successful bind must be completed on the >connection</p>
  </blockquote>
  
  <p>And if I try to connect with my credentials, which are <em>supposed</em> to be valid since I'm connected to the domain with it... I get : <br></p>
  
  <blockquote>
    <p>ORA-31202: DBMS_LDAP: LDAP client/server error
    Invalid credentials<br>
    80090308: LdapErr: DSID-0C090334, 
    comment: AcceptSecurityContext error</p>
  </blockquote>
  
  <p>Could it be possible that the Active Directory doesn't allow external LDAP actions like these ones?</p>
  
  <p><strong>Edit 2</strong><br>
  Taking a look at the 'result' variable, in C#, I get this value for the 'Path' property : <br>
  LDAP://SERVER_OR_DOMAIN/CN=LAST_NAME\,FIRST_NAME,OU=OU1,OU=OU2,OU=OU3,OU=OU4,DC=SERVER_NAME,DC=EXT1,DC=EXT2</p>
  
  <p>Maybe with these info you can help me solve the issue, it might be possible that the AD doesn't allow anonymous connection. Knowing the 'Path' propery, what would be the 'ldap_base', 'ldap_user' and 'ldap_passwd'?</p>