title: Can not access Active Directory domain controller from remote server
body: <p>I am very new to the LDAP and Active Directory integration portion. Although I successfully configured my local machine to access Active Directory domain controller, when I deployed it on one of our server neither through IP address of the domain nor through domain name it was accessible.</p>
  
  <p>My website is in ASP.NET C#.</p>
  
  <p>It was getting this error:</p>
  
  <blockquote>
    <p>The specified domain either does not exist or could not be contacted.</p>
  </blockquote>
  
  <p>My method written to access AD is here:</p>
  
  <pre><code>private SearchResultCollection sResults { get; set; }
  sResults = null;
  
  public void SearchByUsername(string username)
  {
     try
     {
         // initiate a directory entry
         private const string ldapPath = "LDAP://192.168.0.190/OU=Domain   Users,DC=mydomain,DC=net"                
         dEntry = new DirectoryEntry(ldapPath);
  
         dSearcher = new DirectorySearcher(dEntry);
         dSearcher.Filter = "(&amp;(objectClass=user)(sAMAccountname= " + username +  "))";
  
         performSearch();
         getValues();
      }
      catch (Exception)
      {
          throw;
      }
  }
  
  private void performSearch()
  {
      // perform search in Active Directory
      sResults = dSearcher.FindAll();
  }
  
  private void getValues()
  {
      // loop through results of search
      foreach (SearchResult sResult in sResults)
      {
          Employee emp = new Employee();
  
          emp.CN = getProperty(sResult, "cn");
          emp.FirstName = getProperty(sResult, "givenName");
          emp.LastName = getProperty(sResult, "sn");
          emp.Username = getProperty(sResult, "sAMAccountname");
          emp.Email = getProperty(sResult, "mail");
  
          Employees.Add(emp);
      }
  }
  </code></pre>
  
  <p>Above method works very well on my local machine both with IP address and domain name. Server where I am trying this to work is Windows Server 2012 R2.</p>
  
  <p>I ran command <code>nltest /dclist:mydomain.net</code> and made sure that the server is within the domain as it returned me details. i.e. DC name, IP address, domain name. </p>
  
  <p>Is there any syntactical issue I have run into? OR is it related to configuration issue like DNS ?</p>
  
  <p>Also, like to mention as I tried searching about this on www.serverfault.com but couldn't gather much details.</p>
  
  <p>Please suggest me direction.</p>