Using ADO to Search an LDAP Directory Using Visual Basic

   

Using ADO to Search an LDAP Directory Using Visual Basic

With the Windows NT provider, you were often forced to combine conditionals with enumeration functions to find data in the namespace. The LDAP provider allows you to use alternate methods for searching the namespace, such as IDirectorySearch (non-automation languages only) and ADO. With ADO at your command, you can use enumeration functions for what they are truly intended: enumerating subordinate entries.

Using ADO against an LDAP directory is incredibly fast and returns an ADO recordset that can be easily displayed record by record using a While Wend loop. An additional advantage to using ADO and the ADsDSOObject provider is that you can use ANSI-SQL syntax to search the LDAP directory, thus avoiding the need to learn LDAP filter syntax (a true blessing indeed!).

Note

To use the following code sample, you must have ADO installed on your development workstation. You can obtain the ADO libraries by downloading the Microsoft Data Access Components from http://www.microsoft.com/data

After you have run the setup routine, you must set a reference to the library in Visual Basic by selecting the Project menu and clicking the References entry. When the References dialog box appears, simply select Microsoft ADO 2.X Library .


Use the following Visual Basic code to search the Airius sample directory for all users with their sn attribute assigned to Carter :

 Dim Connection As ADODB.Connection Dim RS As ADODB.Recordset Dim Entry As String Dim Index As Long Index = 0 Set Connection = New ADODB.Connection Connection.Provider = "ADsDSOObject" Connection.Open "ADSI" Set RS = Connection.Execute("SELECT cn,telephonenumber FROM 'LDAP://LDAP_SERVER/ graphics/ccc.gif o=airius.com/ou=people' WHERE sn='carter'") While Not RS.EOF     For i = 0 To RS.Fields.Count - 1         If RS.Fields(i).Type = adVariant And Not (IsNull(RS.Fields(i).Value)) Then             For j = LBound(RS.Fields(i).Value) To UBound(RS.Fields(i).Value)                Entry = Entry&RS.Fields(i).Value(j)&vbTab             Next j         Else              Entry = Entry&RS.Fields(i).Value&vbTab         End If         If Index = RS.Fields.Count - 1 Then             Debug.Print Entry         End If         Index = Index + 1     Next i     Entry = ""     Index = 0     RS.MoveNext Wend 

   
Top


Windows NT. 2000 ADSI Scripting for System Administration
Windows NT/2000 ADSI Scripting for System Administration
ISBN: 1578702194
EAN: 2147483647
Year: 2000
Pages: 194
Authors: Thomas Eck

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net