DirectorySearcher maintains active TCP LDAP connection
am 03.01.2008 07:02:01 von MCDONAMWI am writing a little program in vb.net to return a collections of AD
properties to validate some information in AD. I'm noticing something
strange in that I cannot get my program to release the LDAP connection after
it's done doing what it needs to do. It will only close the connection when
the application is completely closed. I'm verifying the actual TCP
connection using TCPView from www.sysinternals.com.
As soon as I create the directorySearcher object (dirSearcher = new
directorySearcher(dirEntry)), the connection is made to my server.
I'm using a try, catch, finally block. In my finally section, I'm trying
dirEntry.close and dirSearcher.dispose, but the LDAP connection persists.
I've even gone as far as adding gc.collect to force a collection after I
close/dispose, but that had no effect either.
Am I missing something really easy here or is this a potential bug? I can't
see this as correct functionality as once an object is disposed/closed, the
connection it used should also close.
Further info: I use one directory entry, and one directory searcher object
based on the dirEntry. I do all my work from the actual search results
instead of creating additional dirEntries for each object returned in my
collection. This is strictly a directorySearch. I'm not doing any
additional functionality to the returned objects themselves, thus not
requiring the additional directory entries.
TIA!