Search in VB.NET Drag and Drop LDAP Server

My administrators informed me that one of my applications is actually clogging up one of our LDAP servers. I have looked through the code several times, but I see no way to limit the number of times I have to hit the LDAP. So now I decided to look at how I actually get the data to see if there is a better way. I have not developed the actual data model I am using and I am not sure if this is the System.DirectoryServices.Protocols library.

I would really appreciate if someone more familiar with using .NET LDAP providers could give me some advice. Here is the function I use to find records on our LDAP server:

    <DirectoryServicesPermission(SecurityAction.LinkDemand, Unrestricted:=True)> _
    Public Overloads Shared Function GetSearchResultEntry(ByVal connection As LdapConnection, ByVal searchDirectoryPath As String, ByVal filter As String, _
                                          ByVal attributes As String(), ByVal scope As Protocols.SearchScope) As SearchResultEntry

        If connection Is Nothing Then
            Throw New ArgumentNullException("connection", "An ldap connection must be provided in order to search for a directory.")
        End If

        If Strings.IsNullOrBlank(searchDirectoryPath) Then
            Throw New ArgumentException("A directory path must be provided in order to search for a directory.", "searchDirectoryPath")
        End If

        If Strings.IsNullOrBlank(filter) Then
            Throw New ArgumentException("A search filter must be provided in order to search for a directory.", "filter")
        End If

        Dim resp As SearchResponse = CType(connection.SendRequest(New SearchRequest(searchDirectoryPath, filter, scope, attributes)), SearchResponse)

        If resp.Entries.Count > 0 Then
            Return resp.Entries(0)
        End If

        Return Nothing

    End Function

      

Is it possible that the .NET LDAP provider is a bit slow? If anyone has code examples of how they get to LDAP in their stores, that would be great.

Anyway, thanks in advance for your help.

Thanks,
CM

+1


source to share


1 answer


Two things:



  • You only need 1 entry. This code looks like it will return all the results for a particular query. You can try to search for a single result query style.
  • Otherwise, I doubt there is much that can be done to make this bit easier on the server. You can see if there is a way to call this function less often - perhaps by caching the results.
+1


source







All Articles