473,385 Members | 1,375 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

LDAP ports not closing

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

Nov 8 '05 #1
2 4892
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,

--
Rainier van Slingerlandt
(Freelance trainer/consultant/developer)
www.slingerlandt.com
"Daneel" wrote:
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

Nov 9 '05 #2
That was it!

Thank you very much.

"Rainier [MCT]" wrote:
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,

--
Rainier van Slingerlandt
(Freelance trainer/consultant/developer)
www.slingerlandt.com
"Daneel" wrote:
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

Nov 10 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: ngiven | last post by:
Dear PHP Programmers, Here is what I have: PHP Version 4.3.8 LDAP Support enabled RCS Version $Id: ldap.c,v 1.130.2.10 2004/06/01 21:05:33 iliaa Exp $ Total Links 0/unlimited API Version...
1
by: Kim Berry | last post by:
This may not be the correct place to post this; however, please bear with me. Platform: Solaris 9 iPlanet Web Server Java Servlets/JSP website I have a servlet that displays the contents of...
7
by: Amar | last post by:
I am trying to connect to my college LDAP directory using ASP.NET. This LDap does not have security as it returns only user demographic information. i do not need to bind with a username or...
2
by: Mantorok | last post by:
Hi I use RemotingCOnfiguration.Configure("App.config") to configure my ports, however sometimes after I have closed the app and restart it throws an exception "Only one usage of each socket...
7
by: Sync Walantaji | last post by:
Hi, I would like to write a asp.net winform program to authenticate users on Active Directory. Can I do this with asp.net if the IIS server is not part of the Active directory domain? Is...
2
by: Daneel | last post by:
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...
0
by: Suman | last post by:
Hi All,    I am trying out a web based chat-server program on a server machine. I opened few PORTS during my trial runs and somehow the telnet session got crashed and I couldn't...
0
by: rbukkara | last post by:
Hi, I have got the following error while trying to add a user in the LDAP Directory. javax.naming.NameNotFoundException: ; remaining name 'uid=vassila,ou=People,dc=cs,dc=uno,dc=edu' I have...
0
by: Sells, Fred | last post by:
I'm running python 2.5 (or 2.4) in an XP environment. I downloaded and installed the .dll's from OpenLDAP-2.4.8+OpenSSL-0.9.8g-Win32.zip and copied the .dll's in c:/windows/system32 as instructed...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.