Consultor Eletrônico



Kbase 20947: What Connection Mode? Single-User, Multi-User or Neither?
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   10/16/2008
Status: Unverified

GOAL:

How to programmatically determine whether a user is connected to a single-user database, a multi-user database, or no database at all.

FIX:

There are at least two possible ways to use Progress 4GL to determine the current database connection mode. This solution provides the 4GL code for the direct and more elegant method.

The solution uses the DBPARAM function that returns a character string in the form of a comma-separated character list of the database connection parameters or the unknown value (?) if the database is not connected.

It also uses the INDEX function, and passes it the name of the database and the "-1" strings as parameters. The function is expected to return an integer or the unknown value (?).

If the INDEX function is operating on the name of the database and the "-1" strings returns the integer value of zero (0), connection was established to the specified database in multi-user mode.

If the INDEX function is operating on the name of the database and the "-1" strings returns a positive integer value, connection was established to the specified database in single-user mode.

Lastly, if the INDEX function is operating on the name of the database and the "-1" strings returns the unknown value (?), connection was not established to the specified database at all.

The following assumes you are dealing with the Progress sample Sports database. The code is as follows:

IF INDEX(DBPARAM("sports"), "-1" ) > 0 THEN
MESSAGE "Connected in single-user mode"
VIEW-AS ALERT-BOX INFO BUTTONS OK.
ELSE
IF INDEX(DBPARAM("sports"), "-1" ) = 0 THEN
MESSAGE "Connected in multi-under mode"
VIEW-AS ALERT-BOX INFO BUTTONS OK.
ELSE
IF INDEX(DBPARAM("sports"), "-1" ) = ? THEN
MESSAGE "Not Connected to a database"
VIEW-AS ALERT-BOX INFO BUTTONS OK.