directory-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stefan Seelmann <>
Subject Re: Error: The directory service is not available
Date Wed, 28 Oct 2009 08:55:28 GMT
Hi Pepe,

I already replied to the dev@ mailing list, here again.

Gaetano Pepe wrote:
> Hi
> I use apache directory server and I would add a new user ....I use Visual Studio and
mx OS is windows vista.
> the code is this:
> public static void prova(string FullName)
>         {          
>             DirectoryEntry container;
>             DirectoryEntries ChildEntry;
>             container = new DirectoryEntry("LDAP://localhost:389/ou=users,ou=system,dc=example,dc=com",
"uid=admin,ou=system", "secret");

Please check if "ou=users,ou=system,dc=example,dc=com" really exists.
"ou=users,ou=system" exists in a default installation.

To do a simple bind you need to use a bind DN and specify the right
authentication type (AuthenticationTypes.None). I'm not sure if other
authentication types work with non-AD servers.

>             try
>             {
>                 ChildEntry = container.Children;
>                 DirectoryEntry NewEntry = ChildEntry.Add("cn=" + FullName, "user");

Apache Directory Server doesn't contain the "user" object class. So if
you haven't added it to the schema you should use another object class
(e.g. inetOrgPerson)

Before you commit the changes you need to add all the other mandatory
attributes (cn and sn for inetOrgPerson).

>                 NewEntry.CommitChanges();
>                 NewEntry.Close();
>             }
>             catch (Exception ex)
>             {
>                 throw new Exception("Error " + ex.Message);
>             }
>          }
> The problem is that I have this type of error:The directory service is not available.
> I tried changing the port with the 10389 but I'm still the same error. 
>  The server I think it works, I've tested with apache directory studio.

IMHO the error message produced by the System.DirectoryServices API is
not very helpful. I'd recommend to use a network monitor like Wireshark
to find out the problems.

Here is your modified code that works for me:

    DirectoryEntry Container = new DirectoryEntry(
        "uid=admin,ou=system", "secret", AuthenticationTypes.None);

    DirectoryEntries ChildEntries = Container.Children;
    DirectoryEntry NewEntry = ChildEntries.Add(
        "cn=" + FullName, "inetOrgPerson");

catch (Exception ex)

BTW: There is a much better C# LDAP API from Novell, see [1][2]. There
are also many examples available.

Kind Regards,


View raw message