LDAP ports not closing

G

Guest

The following code gets attributes from an LDAP server. It works several
times, but then returns a "server is not operational" error for all
subsequent calls. A "netstat -na" on the Windows 2003 server shows that
there are several TCP connections to port 636 stuck in "close_wait" state.
Is there a way to close these connections with VB?

The code:

Const rootPath As String = "LDAP://directory.acme.com:636/o=acme"
Const ldapFilter As String = Nothing
Dim ldapKey As String() = {"acmeguid"}
Dim path As String
Dim user As String
Try
Dim root As New DirectoryEntry(rootPath, Nothing, Nothing,
AuthenticationTypes.FastBind Or AuthenticationTypes.SecureSocketsLayer)
root.RefreshCache() ' force bind
Dim rootSearch = New DirectorySearcher(root, "uid=" & uid,
ldapKey)
root.Close()
Dim rootSRC As SearchResultCollection = rootSearch.FindAll()
rootSearch.Dispose()
Dim rootSR As SearchResult
If rootSRC.Count > 0 Then
rootSR = rootSRC(0)
End If
If IsNothing(rootSR) Then
Throw New Exception("Invalid username and/or password")
Exit Sub
Else
path = rootSR.Path
user = Regex.Split(path, "/")(3)
End If
Catch ex As System.Runtime.InteropServices.COMException
Throw New Exception("COMException: " & ex.Message)
Exit Sub
Catch ex As Exception
Throw New Exception("Exception: " & ex.Message)
Exit Sub
Catch
Throw New Exception("Unknown error")
Exit Sub
End Try
Try
Dim de As New DirectoryEntry(path, user, pwd,
AuthenticationTypes.FastBind Or AuthenticationTypes.SecureSocketsLayer)
de.RefreshCache() ' force bind
Dim ds As New DirectorySearcher(de, ldapFilter, attrToLoad,
SearchScope.Subtree)
de.Close()
Dim src As SearchResultCollection = ds.FindAll()
ds.Dispose()
Dim sr As SearchResult
Dim enumPropNames As System.Collections.IEnumerator
For Each sr In src
enumPropNames = sr.Properties.PropertyNames.GetEnumerator()
While (enumPropNames.MoveNext() = True)
ldapAttributes.Add(enumPropNames.Current.ToString(),
sr.Properties(enumPropNames.Current.ToString())(0).ToString())
End While
Next
Catch ex As System.Runtime.InteropServices.COMException
Throw New Exception("COMException: " & ex.Message)
Exit Sub
Catch ex As Exception
Throw New Exception("Exception: " & ex.Message)
Exit Sub
Catch
Throw New Exception("Unknown error")
Exit Sub
End Try
 
G

Guest

Hi Daneel,

It seems you are cleaning up your resources nicely, Disposing everything,
setting them to nothing etc.

Your just not doing this in a finally clause. Maybe there is a glidge slowly
eating your resources....

Kind Regards,
 
G

Guest

That was it!

Thank you very much.



Rainier said:
Hi Daneel,

It seems you are cleaning up your resources nicely, Disposing everything,
setting them to nothing etc.

Your just not doing this in a finally clause. Maybe there is a glidge slowly
eating your resources....

Kind Regards,
 

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