Showing posts with label AFTER LOGON ON DATABASE Trigger issue. Show all posts
Showing posts with label AFTER LOGON ON DATABASE Trigger issue. Show all posts

Wednesday, 16 July 2014

Can to connect to database due to AFTER LOGON ON DATABASE Trigger issue

Database connectivity issue related to AFTER LOGON ON DATABASE Trigger

Senario: I have create a trigger with AFTER LOGON ON DATABASE
to prevent specific user from specific hosts using following syntax

CREATE OR REPLACE TRIGGER block_user_from_prod
  AFTER LOGON ON DATABASE
DECLARE
  v_username sys.v_$session.username%TYPE;
  v_host varchar2(20);
BEGIN
  SELECT username,SYS_CONTEXT ('USERENV', 'SERVER_HOST') INTO v_username,v_host
    FROM sys.v_$session
  WHERE  upper(username) ='TEST';

  IF UPPER(v_username)='TEST' and LOWER(v_host)='oracledbdr1'
  THEN
     RAISE_APPLICATION_ERROR(-20000, 'Please use Database Server IP as 192.168.10.7 instead 192.168.10.2 ');
  END IF;
  
  EXCEPTION
    WHEN NO_DATA_FOUND THEN
        DBMS_OUTPUT.PUT_LINE ('hello');
END;
/

But after creating the trigger i couldn't connect to database even from database server itself.
After that i have shutdown the database and startup again but couldn't connect to database.

Note: I have tried to disable or drop the trigger but unable to do this.

Solution:

Step1: create pfile='/tmp/test.ora' from spfile;

Step2: shutdown immediate

Step3: startup pfile=/tmp/test.ora

Step4: alter TRIGGER block_user_from_prod disable;

Step5: drop TRIGGER block_user_from_prod disable;

Step6: Now try to connect database from other session or user.