How to kill inactive session from Forms

Technology: Oracle Forms 6i, Oracle Database 9i or greater

One of my friend asked how we can kill an inactive session of forms. In an Application server environment this can be attained by modifying none of the application. But as the version is not of our discussion it will not be discussed here.

Here is how we have attained such a result:

We have to use the D2KWUTIL.PLL. In the WHEN-NEW-FORM-INSTANCE trigger provide the following code:
declare
lwindow PLS_INTEGER;
ltimer TIMER;
begin
lwindow := get_window_property(FORMS_MDI_WINDOW,WINDOW_HANDLE);
Win_API_Session.Timeout_Start_Timer(lwindow);
ltimer := Create_Timer('TIMER1',1000,repeat);
end;

In WHEN-TIMER-EXPIRED trigger provide the following code:
begin
if upper(get_application_property(TIMER_NAME)) = 'TIMER1' then
:control.inactive_time := Win_api_session.Timeout_Get_Inactive_Time;
if : control.inactive_time > 120 then
Win_API_Session.timeout_delete_timer;
exit_form (NO_VALIDATE);
end if;
end if;
end;

Control is a block and inactive_timer is a text item. It need not be displayed in any canvas.

2 comments :

  1. Is this what you meant in English?
    Oi, I found yours blog for google tá well interesting I liked this post. When to give gives passed for mine blog, is on personalized t-shirts, shows step by step as to create a well personalized t-shirt way. Until more.

    ReplyDelete
  2. hi,

    i was suppose to create a trigger where it would stop a specific user with the osuser and username to access the database.

    from a trigger i converted to pl/sql due to i like blocks better, Anyways code is
    declare
    cursor c1 is
    select username,osuser,sid,serial# from v$session where username='FLASHY' and osuser='oracle';

    v_username varchar2(30);
    v_osuser varchar2(20);
    v_sid number(20);
    v_serial number(20);
    v_killstatement VARCHAR2(1000);
    v_status varchar2(20);

    BEGIN
    OPEN c1;
    LOOP
    -- begin
    -- select username,osuser,sid INTO v_username, v_osuser, v_sid from v$session where username='FLASHY' and osuser='oracle';
    -- exceptionSS
    -- when NO_DATA_FOUND then
    -- raise_application_error (-20001,'no data available.');
    --end; (
    --iF SOMEONE WANTS SOME DATA TO BE OUTPUTTED THEN USE THE ABOVE !!!
    FETCH c1 INTO v_username, v_osuser, v_sid, v_serial;
    EXIT WHEN c1%NOTFOUND;
    --dbms_output.put_line(v_username ||' ' || v_sid ||'comma'||' ' );
    IF v_username = 'FLASHY' AND v_osuser = 'oracle' THEN
    dbms_output.put_line ('you cannot login with this username and password');
    --dbms_output.put_line (v_osuser);
    --dbms_output.put_line (v_sid);
    --dbms_output.put_line (v_status);
    v_killstatement:='alter system kill session ' ||' ' || v_sid ||','||' '|| v_serial|| '';
    EXECUTE IMMEDIATE v_killstatement;
    raise_application_error(-20000,'You are not allowed to login using the program');

    END IF;
    -- EXIT
    -- WHEN c1%NOTFOUND;
    -- dbms_output.put_line ('hello');
    END LOOP;
    CLOSE c1;
    END;

    ReplyDelete