This Article provides a code example to disconnect a database user from a client running on a remote machine (to the database) using an AppServer.
The "proshut -C disconnect" command can only be run on the same machine the database is started. While a remote PROSHUT session is able to disconnect a database user by choosing Option 1 Disconnect a User from the menu presented and entering the user number to disconnect:
proshut dbname -H <host> -S <port> -Mm <bytes>
The same remote proshut session is not able to disconnect that user by adding the '-C disconnect' parameter to the command line. Use of this parameter is limited to local non-networked connections only, you cannot use the "-S" with "disconnect". It will fail with "You cannot run the DISCONNECT from a remote machine. (2259)"
The code example below consists of two ABL programs:
- Apps_shut.p runs on the AppServer side and disconnects the user with the number contained in shut_id.
- Cli_shut.p runs on the client side. It uses the VST table _connect, to detect users that are connected remotely and lists them in a browser. To disconnect a user, select the user and press the "shut" button.
The sample code programs Cli_shut.p and Apps_shut.p are also attached in the file Remote_shut.zip
To implement disconnecting users from a client running on another machine:
1. On the Server side put the program Apps_shut.p in a directory that is included in the PROPATH.
Replace the database name with the path and database you want to disconnect the users from.
/* App_shut.p program set the path and the database name to disconnect users from */
DEFINE INPUT PARAMETER shut_id AS INTEGER.
OS-COMMAND SILENT VALUE("proshut dbname -C disconnect " + TRIM(STRING(shut_id,">>>9"))).
MESSAGE "Remote proshut disconnecting user: " + TRIM(STRING(shut_id,">>>9")) .
RETURN.
2. On the C
lient side, execute the following
Cli_shut.p program:
/* Cli_shut.p */
/* This program will run on the client side and will browse the user list with the _Connect VST */
/* If you press the shut button it will disconnect the selected user and exit*/
DEFINE VARIABLE shut_w AS WIDGET NO-UNDO.
DEFINE BUTTON but_shut LABEL "&Shut User".
DEFINE BUTTON but_exit LABEL "&Exit".
DEFINE BUTTON but_refr LABEL "&Refresh".
DEFINE VARIABLE servhdl AS HANDLE.
DEFINE VARIABLE ret AS LOGICAL.
DEFINE VARIABLE shut_db AS CHARACTER.
DEFINE VARIABLE shut_id AS INTEGER.
DEFINE QUERY shut_q FOR _Connect.
DEFINE BROWSE shut_b QUERY shut_q
DISPLAY
_Connect._Connect-Usr
_Connect._Connect-Name
_Connect._Connect-Type
_Connect._Connect-Wait
_Connect._Connect-Wait1
_Connect._Connect-TransID
_Connect._Connect-PID
_Connect._Connect-Server
_Connect._Connect-Time
WITH 15 DOWN.
FORM shut_b
but_shut AT 1
but_refr AT 20
but_exit AT 110
WITH FRAME shut_f
1 DOWN NO-BOX KEEP-TAB-ORDER OVERLAY
SIDE-LABELS NO-UNDERLINE THREE-D
AT COL 1 ROW 1 SIZE 120 BY 14.50
CANCEL-BUTTON but_exit.
ON CHOOSE OF but_shut
DO:
IF AVAILABLE _Connect THEN DO TRANSACTION:
shut_id = _Connect._Connect-Usr.
CREATE SERVER servhdl.
ASSIGN ret = servhdl:CONNECT("-S 5162 -H localhost -AppService asbroker1").
IF ret THEN RUN apps_shut.p ON SERVER servhdl TRANSACTION DISTINCT (INPUT shut_id).
ASSIGN ret = servhdl:DISCONNECT().
DELETE OBJECT servhdl.
END.
END.
ON CHOOSE OF but_refr
DO:
RUN open_query IN THIS-PROCEDURE.
END.
CREATE WINDOW shut_w
ASSIGN
HEIGHT = 14.50
WIDTH = 120
STATUS-AREA = NO
MESSAGE-AREA = NO.
RUN open_query IN THIS-PROCEDURE.
VIEW FRAME shut_f IN WINDOW shut_w.
ENABLE ALL WITH FRAME shut_f.
APPLY "cursor-down" TO shut_b.
WAIT-FOR WINDOW-CLOSE OF shut_w OR CHOOSE OF but_exit FOCUS shut_b.
DELETE WIDGET shut_w.
QUIT.
PROCEDURE open_query:
OPEN QUERY shut_q FOR EACH _Connect WHERE _Connect._Connect-Type = "REMC".
END.