Click here to Skip to main content
13,139,569 members (49,897 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Hi all,

Please go through the below code

PrincipalContext ctx = new PrincipalContext(ContextType.Domain, "","CN=Partition1,DC=Somename,DC=com", "AD/Administrator", "password");

While I run this code, I get a error message "The server could not be contacted"

inner exception "The LDAP server is unavailable".

Please let me know what to do.

Exception detail below

System.DirectoryServices.AccountManagement.PrincipalServerDownException was unhandled by user code
  Message=The server could not be contacted.
       at System.DirectoryServices.AccountManagement.PrincipalContext.ReadServerConfig(String serverName, ServerProperties& properties)
       at System.DirectoryServices.AccountManagement.PrincipalContext.DoServerVerifyAndPropRetrieval()
       at System.DirectoryServices.AccountManagement.PrincipalContext..ctor(ContextType contextType, String name, String container, ContextOptions options, String userName, String password)
       at System.DirectoryServices.AccountManagement.PrincipalContext..ctor(ContextType contextType)
       at TestingActiveDirectory._Default.Page_Load(Object sender, EventArgs e) in d:\TestingActiveDirectory\TestingActiveDirectory\Default.aspx.cs:line 88
       at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
       at System.Web.UI.Control.OnLoad(EventArgs e)
       at System.Web.UI.Control.LoadRecursive()
       at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
  InnerException: System.DirectoryServices.Protocols.LdapException
       Message=The LDAP server is unavailable.
            at System.DirectoryServices.Protocols.LdapConnection.Connect()
            at System.DirectoryServices.Protocols.LdapConnection.SendRequestHelper(DirectoryRequest request, Int32& messageID)
            at System.DirectoryServices.Protocols.LdapConnection.SendRequest(DirectoryRequest request, TimeSpan requestTimeout)
            at System.DirectoryServices.Protocols.LdapConnection.SendRequest(DirectoryRequest request)
            at System.DirectoryServices.AccountManagement.PrincipalContext.ReadServerConfig(String serverName, ServerProperties& properties)

[edit]Code block added[/edit]
Posted 11-Jun-13 23:13pm
Updated 12-Jun-13 0:03am
Bernhard Hiller 12-Jun-13 6:39am
Is that code run from a Windows application or by the web server?
Can you ping the LDAP server? What about the firewalls? Does the code work when run under a different user account?
Vignan Galla 12-Jun-13 7:51am
Thanks for your reply...
This code is run locally from a web application.
The computer and the server are on the same domain.
Yes, I am able to ping the LDAP server,please go through below.

Pinging [] with 32 bytes of data:
Reply from bytes=32 time<1ms TTL=128
Reply from bytes=32 time<1ms TTL=128
Reply from bytes=32 time<1ms TTL=128
Reply from bytes=32 time<1ms TTL=128

Ping statistics for
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 0ms, Average = 0ms

Regarding firewalls: for Domain,Private and Public windows firewall is off.
Do I need to disable/enable anything more regarding firewalls? Please help.

No the code does not run under any user account.
RyanDev 23-Sep-14 15:40pm
The error seems pretty clear. It can't connect to the LDAP server.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Please help me on this. I also stuck here and doesnt find any solution
RyanDev 23-Sep-14 15:39pm
This is not a solution. Please remove it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.170915.1 | Last Updated 23 Sep 2014
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100