0

I am using Domain object in System.DirectoryServices.ActiveDirectory namespace. Whenever I query domain details using Domain.GetCurrentDomain or Domain.GetDomain, it establishes connection with domain controller. This connection can be seen with netstat -ano|findstr 389 command.

Code:

Domain dom = Domain.GetCurrentDomain();

My question is, how to close the connection? The only way I can close the connection is to dispose the Domain object. Since I have cached the Domain object in my code I don't want dispose it. The problem it raises is, 'ESTABLISHED' state remains for some time later it changes to 'CLOSE_WAIT'.

netstat -ano | findstr 389

  TCP    10.241.93.168:51291    154.1.124.156:389      CLOSE_WAIT      8028
  TCP    10.241.93.168:51297    154.1.124.154:389      CLOSE_WAIT      8028
  TCP    10.241.93.168:51302    154.1.124.158:389      CLOSE_WAIT      8028
  TCP    10.241.93.168:51320    154.1.124.155:389      CLOSE_WAIT      8028
  TCP    10.241.93.168:51323    154.1.124.153:389      CLOSE_WAIT      8028
  TCP    10.241.93.168:51332    154.1.124.157:389      CLOSE_WAIT      8028
  TCP    10.241.93.168:53399    148.86.153.162:389     CLOSE_WAIT      8028
  TCP    10.241.93.168:53436    139.172.150.15:389     CLOSE_WAIT      8028

For security reason I need to eliminate this stale connection. Do let me know if you have any suggestions.

Thanks,Santhosh

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • You've already answered "how do you close the connection" - you do it by disposing of the object. If "I don't want to dispose it", that is a *conflict* in your requirements (close connection/avoid dispose). *You* need to decide which way you're going to resolve it. – Damien_The_Unbeliever Jan 03 '13 at 07:16

1 Answers1

1

I bet the that the Domain object keeps the connection open since you can perform operations on it.

If you just need to get some domain information you should probably read it and store it in a simple class and then dispose the Domain.

jgauffin
  • 99,844
  • 45
  • 235
  • 372