Click here to Skip to main content
12,070,942 members (61,718 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# ASP.NET C#4.0
Hi all,

Please go through the below code

PrincipalContext ctx = new PrincipalContext(ContextType.Domain, "ad.domain.com","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
  HResult=-2146233087
  Message=The server could not be contacted.
  Source=System.DirectoryServices.AccountManagement
  StackTrace:
       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
       HResult=-2146233088
       Message=The LDAP server is unavailable.
       Source=System.DirectoryServices.Protocols
       ErrorCode=81
       StackTrace:
            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)
       InnerException:

[edit]Code block added[/edit]
Posted 12-Jun-13 0:13am
Edited 12-Jun-13 1:03am
Nelek90.4K
v2
Comments
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 WIN-1CN76R547BQ.ad.domain.com [192.168.1.38] with 32 bytes of data:
Reply from 192.168.1.38: bytes=32 time<1ms TTL=128
Reply from 192.168.1.38: bytes=32 time<1ms TTL=128
Reply from 192.168.1.38: bytes=32 time<1ms TTL=128
Reply from 192.168.1.38: bytes=32 time<1ms TTL=128

Ping statistics for 192.168.1.38:
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
 
good
Please Sign up or sign in to vote.

Solution 1

Please help me on this. I also stuck here and doesnt find any solution
  Permalink  
Comments
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 | Mobile
Web03 | 2.8.160208.1 | Last Updated 23 Sep 2014
Copyright © CodeProject, 1999-2016
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