Directory Services

ldap_connect

The ldap_connect function establishes a connection with the server.

ULONG ldap_connect(
  LDAP* ld,
  LDAP_TIMEVAL* timeout
);

Parameters

ld
[in] The session handle obtained from ldap_init.
timeout
[in] A pointer to an LDAP_TIMEVAL structure that specifies the number of seconds to spend in an attempt to establish a connection before a timeout. If NULL, the function uses a default timeout value.

Return Values

If the function succeeds, LDAP_SUCCESS is returned.

If the function fails, an error code is returned. For more information, see Return Values.

Remarks

Although it is not required that a client call ldap_connect to establish a connection to the server, it is good programming practice to do so. If the connection does not exist, other functions, for example, ldap_bind_s, perform the call internally. However, if you have to troubleshoot this part of your application, establishing the connection prior to making the call to some other function, for example ldap_bind_s, will also separate the possible problems if the connection fails. Alternately, you can specify additional options on the connection block. For example, a client can call ldap_init to initialize a session, then call ldap_connect, with a non-NULL timeout parameter value, to connect to the server with a specified time-out.

If the call to ldap_connect succeeds, the client is connected to the LDAP server as an anonymous user. The session handle should be freed with a call to ldap_unbind when it is no longer required.

If the ldap_connect call fails, the session handle should be freed with a call to ldap_unbind when no longer required for error recovery.

Requirements

Client: Included in Windows XP and Windows 2000 Professional.
Server: Included in Windows Server 2003 and Windows 2000 Server.
Redistributable: Requires Active Directory Client Extension on Windows NT 4.0 SP6a and Windows 95/98/Me.
Header: Declared in Winldap.h.
Library: Use Wldap32.lib.

See Also

Establishing an LDAP Session, Functions, LDAP_TIMEVAL, ldap_init, ldap_unbind, Return Values