GET-DB-CLIENT function

Returns the handle to a copy of the sealed client-principal object that represents the user identity for the specified database connection.

Syntax

GET-DB-CLIENT ( [db-exp] )
db-exp
An optional character expression that evaluates to a case-insensitive logical or alias name of an OpenEdge RDBMS. This expression can be unspecified or evaluate to the Unknown value (?) only if there is a single OpenEdge database connection, in which case the client-principal object handle is returned for that connection.

Example

In the following procedure fragment, GET-DB-CLIENT returns the sealed client-principal that the CONNECT statement creates from authenticating a new connection to the sports2000 database based on the user ID (cUserID) and password (cPasswd) that are passed as input parameters:

DEFINE INPUT PARAMETER cUserID AS CHARACTER NO-UNDO.
DEFINE INPUT PARAMETER cPasswd AS CHARACTER NO-UNDO.

DEFINE VARIABLE hCP AS HANDLE NO-UNDO.

CONNECT C:\OpenEdge\WRK\db\Sports2000 
  VALUE( "-U " + cUserID +
        " -P " + "oech1::" + AUDIT-POLICY:ENCRYPT-AUDIT-MAC-KEY(cPasswd))
  -H dbserver -S 1900 NO-ERROR.
ASSIGN hCP = GET-DB-CLIENT("sports2000").

SECURITY-POLICY:LOAD-DOMAINS("sports2000").
SECURITY-POLICY:SET-CLIENT(hCP).

DELETE OBJECT hCP.
ASSIGN hCP = ?.

The fragment then loads the ABL session domain registry from the sports2000 database and uses the returned client-principal object (hCP) to set the session identity (and the identities of any other available database connections) to the existing sports2000 connection identity. The fragment ends by deleting the client-principal, which is no longer needed for the session.

Typically, you also check the LOGIN-STATE attribute and STATE-DETAIL attribute on the client-principal object handle, along with other error handling mechanisms, to identity if both the database connection and its authentication are successful.

Note also that this fragment encrypts the password value (cPasswd) and concatenates it with a prefix in a form that OpenEdge expects for encrypted passwords. For more information, see the ENCRYPT-AUDIT-MAC-KEY( ) method reference entry.

Notes

See also

Client-principal object handle, CONNECT statement, GET-CLIENT( ) method, SET-DB-CLIENT function, SETUSERID function