Reading from LDAP searchresults

E

Eric

Hi,

After I retrieved data from my companies AD, done in less then 1 sec, I want
to read that data into a dataset.

I do that with:
Dim cn() As Object

For Each src As SearchResult In sr
rw = dsData.Tables("managers").NewRow
If src.GetDirectoryEntry().Properties("cn").Value IsNot Nothing Then
cn = src.GetDirectoryEntry.Properties("cn").Value
rw("fullname") = cn(1).ToString
End If
If src.GetDirectoryEntry().Properties("mail").Value IsNot Nothing Then
rw("email") =
src.GetDirectoryEntry().Properties("mail").Value.ToString
End If
dsData.Tables("managers").Rows.Add(rw)
Next
Catch ex As Exception
Me.txtLijst.Text = ex.Message
End Try

It takes up to 20 seconds to read this information from the searchresults
and it's only 21 names.

How can I speed this up?

rg,
Eric
 
C

Chris Dent

If you're only reading values you do not need all those calls to
GetDirectoryEntry, it's quite a heavy operation and exactly why it takes
so long. You only need to call GetDirectoryEntry if you're making
changes to the object in AD.

For Each src As SearchResult In sr
' src.Properties("cn") is a PropertyValueCollection - better check
this test for null values though
If src.Properties("cn") IsNot Nothing Then
' Get the value at the first index, will be 0 for all single-value
properties
cn = src.Properties("cn")(0)
...

If the property is not loaded you would need to take a look at the
DirectorySearcher and the properties you've chosen to load (if any).
Some properties, canonicalName for instance, will not be available
unless you explicitly request it.

Chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top