Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Expand Minimize

ldap_connect function

The ldap_connect function establishes a connection with the server.


ULONG ldap_connect(
  _In_ LDAP         *ld,
  _In_ LDAP_TIMEVAL *timeout


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 value

If the function succeeds, LDAP_SUCCESS is returned.

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


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.


Minimum supported client

Windows Vista

Minimum supported server

Windows Server 2003







See also

Establishing an LDAP Session
Return Values



© 2015 Microsoft