暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

创建trigge禁止navicat登录

原创 问题归档 2019-03-20
777

问题描述

你好, trigger正常编译,alter日志也有记录,但是navicat可以登录数据库。

trigger内容:

create or replace TRIGGER sys.flaginfo_logon_control
  AFTER LOGON ON DATABASE
DECLARE
  v_sid  varchar2(10);
  v_serial# varchar2(10);
  my_forced_exception EXCEPTION;
  PRAGMA EXCEPTION_INIT(MY_FORCED_EXCEPTION, -20101);
BEGIN
  IF ( sys_context('USERENV', 'SESSION_USER') LIKE ('SYS%')) -- add your username here
   THEN
    IF (UPPER(sys_context('USERENV', 'MODULE')) LIKE '%NAVICAT%'  ) --SQL DEVELOP
     THEN
      
      RAISE my_forced_exception;
    END IF;
  END IF;
EXCEPTION
  WHEN my_forced_exception THEN
    RAISE_APPLICATION_ERROR(-20101,
                            'USER ' ||
                            sys_context('USERENV', 'SESSION_USER') || ' ' ||
                            'MODULE ' ||
                            UPPER(sys_context('USERENV', 'MODULE')) || ' ' || '
                              Logon Action via tool is not allowed');
  WHEN OTHERS THEN
    null;
END;

登录有alter.log有记录

Mon Mar 18 13:07:43 2019
Errors in file /opt/oracle/admin/ltdb/udump/ltdb_ora_22162.trc:
ORA-00604: error occurred at recursive SQL level 1
ORA-20101: USER SYS MODULE NAVICAT PREMIUM@STONEDEMACBOOK-PRO.LOCAL (TNS V1 
                              Logon Action via tool is not allowed
ORA-06512: at line 17
oracle@odb-wx045-s172:~$ more  /opt/oracle/admin/ltdb/udump/ltdb_ora_22162.trc
/opt/oracle/admin/ltdb/udump/ltdb_ora_22162.trc
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
ORACLE_HOME = /opt/oracle/product/10.2.0.4.0/db_1
System name:    Linux
Node name:      odb-wx045-s172
Release:        2.6.32-573.el6.x86_64
Version:        #1 SMP Thu Jul 23 15:44:03 UTC 2015
Machine:        x86_64
Instance name: ltdb
Redo thread mounted by this instance: 1
Oracle process number: 781
Unix process pid: 22162, image: oracle@odb-wx045-s172
*** ACTION NAME:() 2019-03-18 13:07:43.320
*** MODULE NAME:(Navicat Premium@stonedeMacBook-Pro.local (TNS V1) 2019-03-18 13:07:43.320
*** SERVICE NAME:(SYS$USERS) 2019-03-18 13:07:43.320
*** SESSION ID:(4814.13060) 2019-03-18 13:07:43.320
Error in executing triggers on connect internal
*** 2019-03-18 13:07:43.320
ksedmp: internal or fatal error
ORA-00604: error occurred at recursive SQL level 1
ORA-20101: USER SYS MODULE NAVICAT PREMIUM@STONEDEMACBOOK-PRO.LOCAL (TNS V1 
                              Logon Action via tool is not allowed
ORA-06512: at line 17

专家解答

以下这段代码,不要放在Exception里。

RAISE_APPLICATION_ERROR(-20101,
                            'USER ' ||
                            sys_context('USERENV', 'SESSION_USER') || ' ' ||
                            'MODULE ' ||
                            UPPER(sys_context('USERENV', 'MODULE')) || ' ' || '
                              Logon Action via tool is not allowed');

最后修改时间:2019-03-20 21:09:28
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论