From: Eric on
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

From: Chris Dent on

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

Eric wrote:
> 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
>
>