title: How do I query Active Directory using C# and ADODB?
body: <p>Looking for an example of connecting via ADODB to Active Directory using C#.</p>
  
  <p>My goal is to be able to run a lookup to verify that a user is valid in Active Directory based on one that of that users attributes (user id, email address, etc).</p>
  
  <p>[Would like to stress that using ADODB is a requirement for this, using DirectoryServices is not a valid response.]</p>
  
  <p>My current approach isn't working (exception at cmd.Execute bit):</p>
  
  <pre><code>object parms = null;
  object recs = null;
  ADODB.Connection conn = new ADODB.Connection();
  ADODB.Command cmd = new ADODB.Command();
  ADODB.Recordset rs = new ADODB.Recordset();
  
  conn.Open("Provider=ADsDSOObject",obfsUser,obfsPass,0);
  
  cmd.ActiveConnection = conn;
  cmd.CommandText = "&lt;LDAP://OU=obfsOU,DC=obfsDC,DC=corp,DC=Net&gt;;;name;subtree";
  rs = cmd.Execute(out recs, ref parms, 0);
  </code></pre>
  
  <p>I'm not sure if/where I'm supposed to provide the server reference and I'm not really sure what the parameteres passed into the cmd.Execute method by ref should be.  Not a ton of documentation out there for connecting to ActiveDirectory from C# via ADODB.</p>
  
  <p>conn.State is returning 1 so I believe I am getting an active connection.  I think the problem is in the parameters passed to the cmd.Execute() method.</p>