Query

Metreos.Native.Ldap.Query

Summary

Query will connect and perform a search on an LDAP server.

Usage

Query performs a search with the specified attributes in the Attributes action parameter and returns the results in a System.Data.DataTable variable. A common practice is to pass this variable into a CustomCode block for parsing the data within it. The following code shows how one would retrieve the an attribute of name cn from every found entry in the DataTable returned by a successful query in a CustomCode block:

Example 20.1. Retrieving an Attribute from an LDAP uery


public static string Execute(DataTable resultsFromQuery, ArrayList allCns)
{
    if(resultsFromQuery != null)
    {
        foreach(DataRow row in resultsFromQuery.Rows)
        {
            string cn = row["cn"] as string;

            if(cn == null || cn == String.Empty)
            {
                // this would presumably be an unexpected error that should be dealt with specific to the application
            }
            else
            {
                allCns.Add(cn);
            }
        }
    }

    return "success";
}


The branch condition returned provides useful information in determining the cause of failure:

ConnectionFailure

ConnectionFailure indicates that it was not possible to connect to the LDAP server.

AuthenticationFailure

AuthenticationFailure indicates that the Username and Password do not have the necessary permissions to bind to the LDAP server.

WriteFailure

SearchFailure indicates that the Query action was unable perform a search on the LDAP server.

Failure

Failureor that the action failed unexpectedly for a non-LDAP protocol related reason.

Remarks

None.

Action Parameters
Parameter Name.NET TypeDefaultDescription
LdapServerHost *System.StringThe IP address or host name of the LDAP server.
LdapServerPortSystem.UInt320The port of the LDAP server.
UsernameSystem.StringA user that has the appropriate permissions to search with.
PasswordSystem.StringThe password of the user specified in the Username action parameter.
BaseDnSystem.StringThe base DN to query on.
SearchFilterSystem.StringThe LDAP protocol-formatted search criteria.
AttributesSystem.String[]Specify explicit attributes to return only
VersionSystem.Int323The version of the LDAP server being connected to.
Result Data
Parameter Name.NET TypeDescription
SearchResultsSystem.Data.DataTableA .NET System.Data.DataTable that contains rows and columns corresponding to the entries and attributes returned for the query.
ErrorCodeSystem.Int32An LDAP protocol-specific error code if the action fails due to SearchFailure, AuthenticationFailure, or ConnectionFailure. Note that in any of these three cases, it is not guaranteed that the error code will be populated. The error code will be 0 in the case that no LDAP-specific error code could be found.
ErrorMessageSystem.StringAn LDAP protocol-specific error message if the action fails due to SearchFailure, AuthenticationFailure, or ConnectionFailure. Note that in any of these three cases, it is not guaranteed that the error message will be populated. The error code will be null in the case that no LDAP-specific error message could be found.

Branch Conditions 

failure

No description.

success

No description.

ConnectionFailure

No description.

AuthenticationFailure

No description.

SearchFailure

No description.

NoResults

No description.