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 2 4893
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
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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$) {
}
...
|
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...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
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: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |