OpenLDAP The LDAP server is unavailable

I have been trying to connect to our OpenLDAP server from for the last four days without success. Just before I pull off my hair, could any one out there have a solution that has worked( ie using c# to connect to OpenLDAP server). Apparently I can access the ldap server from putty.exe and do a search. Furthermore, I can use the LDAP server for authentication using a local installation of Drupal CMS without any problems - given that I have added the LDAP module. My problem is doing the same in The specific details are as follows:

Ldap server is hosted on sun solaries. My development machine is running Win XP Service pack 3. The error shows up when I try to call bind with a username and password that I have used successfully with putty.

    string hostNameAndSSLPort = "ipaddress";
    string userName = "username";
    string password = "password";

    // establish a connection
    LdapConnection connection = new LdapConnection(hostNameAndSSLPort);

    // create an LdapSessionOptions object to configure session
    // settings on the connection.
    LdapSessionOptions options = connection.SessionOptions;

    options.ProtocolVersion = 3;

    options.SecureSocketLayer = true;

    connection.AuthType = AuthType.Basic;

    connection.Credential =
    new NetworkCredential(userName , password );

    catch(Exception e){
         lblSecurity.Text = e.Message;

I have even tried starting TLS using options.StartTransportLayerSecurity(null); before calling bind by the same error persists. What could I be doing wrong? Please help!!!!!!!!


I had the same issue. My fix was very similar to the answer above. The issue was the LDAP server was sending back a certificate and the client (our code) wasn't accepting it. So by adding the following line of code, made me celebrate and rip a shirt!

connection.SessionOptions.VerifyServerCertificate = new VerifyServerCertificateCallback((con, cer) => true);

Or in vb terms:

connection.SessionOptions.VerifyServerCertificate = New VerifyServerCertificateCallback(Function(con, cer) True)

See this answer for some example code that works. How do I connect to a locally installed OpenLDAP service?

You mention using XP. I believe there is a hot fix that fixes an issue in the TLS implementation of winldap on XP. You'll have to do some searching around the microsoft site for it. I remember it being buried in a technet page somewhere.

Also don't use TLS with .net/winldap. You'll tear your hair out wondering why your web site randomly pegs out the cpu until it is killed. The answer above has an explanation. Just use SSL.

Code like this:

LdapConnection connection = new LdapConnection(new LdapDirectoryIdentifier(this._domain,     Convert.ToInt32(this._port)));
connection.SessionOptions.VerifyServerCertificate = new VerifyServerCertificateCallback((con, cer) => true);
connection.SessionOptions.ProtocolVersion = 3;
connection.AuthType = AuthType.Basic;       
connection.SessionOptions.SecureSocketLayer = true;

Need Your Help

C# CsvHelper - Missing CsvReader.cs

c# class csv

I am using CsvHelper to read a .CSV file into an html table. I am using .NET MVC 4 and CsvReader I have tried different versions of CsvHelper and am still getting the same error on this l...

Arrays of structures, dynamic allocation

c arrays data-structures struct malloc

I was wondering if my dynamic allocation has been done correctly as I’m currently getting these errors: