Querying an LDAP Server using Active Directory and ADO

In order to do an ADO query against an LDAP database using Active Directory, you must
install the latest version of ADSI (I believe it's currently v2.5). If you are running
Windows 2000, Active Directory is already built in.
To learn more about LDAP, Acitve Directory, and ADSI, check out these resources:

The first thing you will notice that's different, is that the table source becomes the
LDAP server, port and node you wish to query. The field name cn (common
name) is the Attribute value you wish to return. The WHERE part of the
statement returns all items that are an objectClass.
Note: SELECT * does not work with the ADs Provider!

In the next part of the code we instantiate an ADO Connection object, and set it's
provider to: ADSDSOObject.

Since I have setup my Site Server LDAP database to disallow Anonymous acces, I am going
to do an authenticated bind. Doing an authenticated bind to an LDAP Server requires that
the user you are binding to has Administrative rights. The Administrator password must
also be supplied.

Once the connection has been suceesfully opened, the SQL Statement is executed creating
an ADO recordset.

Set rs = Conn.Execute(SQLStmt)

And if all goes well, we should be able to iterate the ADO recordset. The Property
Value is usually returned as a Variant. So keep in mind, that some items may be
returned as Arrays. Generally single value properties are Strings and multi-value
properties are Arrays.

Do While Not rs.EOF Or rs.BOF
ReturnValue = rs.Fields(0)
If IsArray(ReturnValue) Then
For I = LBound(ReturnValue) To UBound(ReturnValue)
If ReturnValue(I) <> "" Then
Response.Write ReturnValue(I) & "<BR>"
End If
Next
Else
Response.Write ReturnValue & "<BR>"
End If
rs.MoveNext
Loop