• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 418
  • Last Modified:

Very slow directory services lookup

I'm having poor performance with this code block and looking for some assistance on where to start troubleshooting it.

I pass a GUID such as: 781b2e1bf45c4045a48732b83de75e4e

It can take up to 11 seconds to return the DN from this.

From what I understand I'm directly binding to the object, no searching or enumeration.

This is in a lab domain with just a few dozen accounts and few hundred groups.

Public Shared Function GetDNfromGUID(ByVal GUID As String) As String
        Dim stopwatch As New Stopwatch

        Dim strDNPath As String = ""
        Dim strDN As String

        strDNPath = "GC://<GUID=" & GUID & ">"

        Dim entry As New DirectoryServices.DirectoryEntry(strDNPath)


            strDN = entry.Properties("distinguishedName").Value.ToString

            Return strDN

        Catch ex As Exception
            Log.l("Error getting DN using GUID: " & GUID & " from path " & strDNPath, ex)
            Return "unknown"


          Log.l1("GetDNfromGUID: " & stopwatch.ElapsedMilliseconds, "StopWatch.log", -3)

        End Try

    End Function

Open in new window

1 Solution
Miguel OzSoftware EngineerCommented:
Change line 9 to:
String.Format("GC://<GUID={0}>", GUID )

Change line 11 to:
Dim entry As New DirectoryServices.DirectoryEntry(strDNPath)
Dim entry As DirectoryEntry = New DirectoryEntry(_path,
 domainAndUsername, pwd, _
mookaAuthor Commented:
Unfortunately these suggestions did not work. I added a new domain controller which responds much faster, I'm blaming hte problem on the DC itself and do not want to invesigate further. Thanks for the suggestions.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now