Search code examples
vb.netwinformsactive-directoryldap

LDAP: Server is not operational for VB.NET Winforms application


We have an application that uses LDAP to get basic information of the user. It has worked fine for years. We also have a testing application that connects to LDAP successfully, unless you perform a Clean Solution; It then fails with Server is not operational. Restore the files from that clean and it works again. Additionally, this error surfaces for users when we publish the application. Users will get that error message for a period of time (1-2 days) and then it will suddenly begin working.

Some other background; We promoted two new DCs and demoted two, and this is when the issues began. LDP.exe connects just fine. Wireshark shows an "LDAP ping" and no other LDAP communication when the connection fails. Wireshark show a SASL/GSSAPI connection when successful.

A snippet of the code for the test application.

        Dim ident As WindowsIdentity = WindowsIdentity.GetCurrent()
        Dim username As String = ident.Name.Substring(ident.Name.IndexOf("\") + 1)
        Dim protocol As String = "LDAP"
        Dim path As String = "domain.com"
        Dim sResult As SearchResult = Nothing
        Dim ldapPath As String = If(String.IsNullOrEmpty(path), String.Format("{0}:", protocol), String.Format("{0}://{1}", protocol, path))
        Using de As New DirectoryEntry(ldapPath)
            Try
                If de.Properties.Count > 0 Then
                    Using adSearch As New DirectorySearcher(de)
                        adSearch.Filter = String.Format("(&(objectClass=user)(sAMAccountName={0}))", username)
                        sResult = adSearch.FindOne()
                    End Using
                End If
            Catch ex As Exception
                Label1.Text = ex.Message
                
            End Try
        End Using
        Return sResult

This sounds very similar to our issue but it is answered with a reboot fixed it. VB.NET LDAP authentication error: "The server is not operational"


Solution