Compartilhar via


Understanding Return Values

Most LDAP functions return a numeric Return Value that indicates whether the function call succeeds or what type of error was encountered. However, this information is sometimes not enough to understand the actual problem.

Requesting the server error code can often help identify the source of the problem. The ldap_get_option function is used with LDAP version 3 to retrieve the server error string.

// ld is the LDAP connection.
PCHAR pServerError;        // Use PWCHAR if Unicode.

ULONG ulRtn = ldap_get_option(ld,LDAP_OPT_SERVER_ERROR,(void*)&pServerError);
if (ulRtn == LDAP_SUCCESS)
{
    // Handle the error string.

    ldap_memfree(pErrorString);
}

The following code example can be used to identify the error code that the server embeds at the start of the server error string.

// ld is the LDAP connection.
ULONG ulServerError;

ULONG ulRtn = ldap_get_option(ld,LDAP_OPT_SERVER_EXT_ERROR,(void*)&ulServerError);
if (ulRtn == LDAP_SUCCESS)
{
    // Handle the error code.
}