Hello,
I am working in PLSQL to create an apex session using APEX_SESSION.CREATE_SESSION. APEX version is 24.1.5.
I have found that if the Security Attributes > Database Session > Initialization PL/SQL Code region is not empty, then APEX_SESSION.CREATE_SESSION fails. If it is empty (i.e. has no initialization code), then creating the session works just fine.
A minimal example is to create a new empty application with a single empty home page (page ID 1). Authentication schemes seem to be unrelated (I have found this issue using database account, LDAP, and no authentication).
Then fill in Security Attributes > Database Session > Initialization PL/SQL Code with any code, for example:
dbms_output.put_line('Hello World');
Then, running the following code:
BEGIN
APEX_DEBUG.ENABLE(9);
APEX_DEBUG.ENABLE_DBMS_OUTPUT();
APEX_UTIL.SET_WORKSPACE('WORKSPACE'); -- Whichever workspace is associated
APEX_SESSION.CREATE_SESSION (
p_app_id => 273, -- The app id, in my case it is 273
p_page_id => 1, -- The page id, in my case it is 1
p_username => 'USERNAME' -- The username, from my experimentation this is quite flexible
);
END;
When the initialization code is not empty, the output contains:
# APEX|-9-|get_builder_session_id: builder session not available %SESSION.get_builder_session_id:646<-%META_DATA.fetch_step_info:445<-%SESSION.create_session:2860<-%SESSION_API.c
# APEX| reate_session:63<-:5
# APEX|-8-|db_session_init g_db_session_init_status=>1,g_db_session_init_code=>dbms_output.put_line('Hello World');%SECURITY.db_session_init:3720<-%SESSION.create_session:2877<-%SESSION_API.create_session:63<-:5
# APEX|-8-|execute p_code=>dbms_output.put_line('Hello World');,p_language=>PLSQL,p_auto_bind_items=>true,p_names.count=>0,p_values.count=>0,p_binds.count=>0,p_parse_as_schema=>APEX_ESG_SCHEMA,p_is_user_schema=>null,p_mle_env=>,p_commit_session_state=>true,p_plugin_cache_key=>
# APEX| %CODE_EXEC.execute:536<-%SECURITY.db_session_init:3729<-%SESSION.create_session:2877<-%SESSION_API.create_session
# APEX| :63<-:5
# APEX|-8-|prepare_array_statement %DYNAMIC_EXEC.prepare_array_statement:526<-%DYNAMIC_EXEC.prepare_statement:227<-%DYNAMIC_EXEC.run_block5:2587<-%C
# APEX| ODE_EXEC_PLSQL.execute_int:130<-%CODE_EXEC_PLSQL.execute:436<-%CODE_EXEC.execute:553<-%SECURITY.db_session_init:3
# APEX| 729<-%SESSION.create_session:2877<-%SESSION_API.create_session:63<-:5
# APEX|-9-|statement empty or no bind variables found. exiting. %DYNAMIC_EXEC.prepare_array_statement:534<-%DYNAMIC_EXEC.prepare_statement:227<-%DYNAMIC_EXEC.run_block5:2587<-%C
# APEX| ODE_EXEC_PLSQL.execute_int:130<-%CODE_EXEC_PLSQL.execute:436<-%CODE_EXEC.execute:553<-%SECURITY.db_session_init:3
# APEX| 729<-%SESSION.create_session:2877<-%SESSION_API.create_session:63<-:5
# APEX|-8-|parse_as_user p_cursor=>1820310001,p_username=>APEX_ESG_SCHEMA,p_use_roles=>false %DYNAMIC_EXEC.parse_as_user:2005<-%DYNAMIC_EXEC.run_block5:2593<-%CODE_EXEC_PLSQL.execute_int:130<-%CODE_EXEC_PLS
# APEX| QL.execute:436<-%CODE_EXEC.execute:553<-%SECURITY.db_session_init:3729<-%SESSION.create_session:2877<-%SESSION_AP
# APEX| I.create_session:63<-:5
# APEX|INF|begin dbms_output.put_line('Hello World'); %DYNAMIC_EXEC.parse_as_user:2010<-%DYNAMIC_EXEC.run_block5:2593<-%CODE_EXEC_PLSQL.execute_int:130<-%CODE_EXEC_PLS
# APEX| QL.execute:436<-%CODE_EXEC.execute:553<-%SECURITY.db_session_init:3729<-%SESSION.create_session:2877<-%SESSION_AP
# APEX| I.create_session:63<-:5
# APEX| |end;
Hello World
# APEX|-8-|stop_apex_engine %.stop_apex_engine:883<-%CODE_EXEC_PLSQL.execute_int:148<-%CODE_EXEC_PLSQL.execute:436<-%CODE_EXEC.execute:553<-%
# APEX| SECURITY.db_session_init:3729<-%SESSION.create_session:2877<-%SESSION_API.create_session:63<-:5
# APEX|-8-|stop_apex_engine %.stop_apex_engine:883<-%ERROR.raise_internal_error:1562<-%SECURITY.db_session_init:3735<-%SESSION.create_session
# APEX| :2877<-%SESSION_API.create_session:63<-:5
BEGIN
*
ERROR at line 1:
ORA-20876: Stop APEX Engine
ORA-06512: at "APEX_240100.WWV_FLOW", line 886
ORA-06512: at "APEX_240100.WWV_FLOW_ERROR", line 1562
ORA-06512: at "APEX_240100.WWV_FLOW_SECURITY", line 3735
ORA-06512: at "APEX_240100.WWV_FLOW_SESSION", line 2877
ORA-06512: at "APEX_240100.WWV_FLOW_SESSION_API", line 63
ORA-06512: at line 5
But when the initialization code is empty, the run is successful. Interestingly the initialization code does actually run, but causes the APEX engine to stop.