title: Get AD ID information from LDAP
body: <p>I use the following code for a web ASP.net application and locally it works fine but on the server it doesn't. It returns an error saying "Table does not exist". In my web config I've put <code>&lt;identity impersonate="true"/&gt;
  </code>
  Any ideas?</p>
  
  <pre><code>#Region " Get AD ID information from LDAP"
  Protected Sub Button1_Click(sender As Object, e As System.EventArgs) Handles Button1.Click
      Dim objRootDSE, objRecordSet, objCommand, objConnection, strDNSDomain As Object
      Dim strQuery, strBase, strFilter, strAttributes As Object
      Dim intCountNumber As Integer
  
      Try
          ' Determine DNS domain name from RootDSE object.
          objRootDSE = GetObject("LDAP://RootDSE")
          strDNSDomain = objRootDSE.Get("defaultNamingContext")
  
          ' Use ADO to search Active Directory.
          objRecordSet = Server.CreateObject("ADODB.recordset")
          objCommand = Server.CreateObject("ADODB.Command")
          objConnection = Server.CreateObject("ADODB.Connection")
          objConnection.Provider = "ADsDSOObject"
          objConnection.Open("Active Directory Provider")
          objCommand.ActiveConnection = objConnection
  
          strBase = "&lt;LDAP://" &amp; strDNSDomain &amp; "&gt;"
          strFilter = "(&amp;(objectCategory=person)(objectClass=user)(samaccountname=" &amp; TB_UserID.Text &amp; "))"
          strAttributes = "sn,givenname,mail,telephoneNumber,"
          strQuery = strBase &amp; ";" &amp; strFilter &amp; ";" &amp; strAttributes &amp; ";subtree"
          objCommand.CommandText = strQuery
          objRecordSet = objCommand.Execute
          intCountNumber = objRecordSet.Fields.Count
          TB_Name.Text = objRecordSet.Fields("givenname").value
          TB_LastName.Text = objRecordSet.Fields.Item("sn").value
          TB_Email.Text = objRecordSet.Fields.Item("mail").value
          TB_Telephone.Text = objRecordSet.Fields.Item("telephoneNumber").value
  
          objRecordSet = Nothing
          objConnection.Close()
      Catch ex As Exception
          DisplayWebMsgBox.WebMsgBox.MessageBox(ex.Message)
      End Try
  
  End Sub
  </code></pre>
  
  <h1>End Region</h1>