title: Error when trying to do LDAP lookup in active directory
body: <p>I'm trying to lookup a user on a local active-directory using java.<br>
  When I try to execute the code, I get the following error:</p>
  
  <p>Error:</p>
  
  <blockquote>
    <p>Lookup failed: javax.naming.NamingException: [LDAP: error code 1 -
    000004DC: Lda pErr: DSID-0C0906DC, comment: In order to perform this
    operation a successful bi nd must be completed on the connection.,
    data 0, v1db1 ]; remaining name: 'CN= John Doe, OU=Accounts'</p>
  </blockquote>
  
  <p>Could anyone tell me what I'm doing wrong?</p>
  
  <p>My code:  </p>
  
  <pre><code>import java.util.Hashtable;    
  import javax.naming.Context;
  import javax.naming.InitialContext;
  import javax.naming.NamingException;
  import javax.naming.ldap.LdapContext;
  
  /**
   * Demonstrates how to look up an object.
   * 
   * usage: java Lookup
   */
  class Lookup {
      public static void main(String[] args) {
  
          // Set up the environment for creating the initial context
          Hashtable env = new Hashtable(11);
          env.put(Context.INITIAL_CONTEXT_FACTORY,
                  "com.sun.jndi.ldap.LdapCtxFactory");
          env.put(Context.PROVIDER_URL,
                  "ldap://localhost:389/DC=PORTAL-UAT,DC=COMPANY,DC=COM");
  
          try {
              // Create the initial context
              Context ctx = new InitialContext(env);
  
              // Perform lookup and cast to target type
              LdapContext b = (LdapContext) ctx
                      .lookup("CN=John Doe,OU=Accounts");
  
              System.out.println(b);
  
              // Close the context
              ctx.close();
          } catch (NamingException e) {
              System.out.println("Lookup failed: " + e);
          }
      }
  }
  </code></pre>