Skip to Main Content
  • Questions
  • Call external procedure C raises ORA-06522: Unable to load DLL

Breadcrumb

Question and Answer

Chris Saxon

Thanks for the question, Omar.

Asked: December 01, 2019 - 12:27 pm UTC

Last updated: December 05, 2019 - 9:51 am UTC

Version: 11g r2

Viewed 1000+ times

You Asked

Hi Tom,

i'm trying to call my first external procedure based C language into my plsql program.

so i set up this configuration :

listener.ora:
SID_LIST_LISTENER =
  (SID_LIST =
 (SID_DESC =
  (SID_NAME = PLSExtProc)
  (ORACLE_HOME = C:\app\Administrateur\product\11.2.0\dbhome_1)
  (PROGRAM = extproc)
  (ENVS="EXTPROC_DLLS=C:\app\Administrateur\product\11.2.0\dbhome_1\BIN\external-db-func.dll")
 )
 
  )

LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = OMAR-PC.TELETIC.DZ)(PORT = 1524))
   (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC))
    )
  )

ADR_BASE_LISTENER = C:\app\Administrateur


tnsnames:
DBORACLE =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = OMAR-PC.TELETIC.DZ)(PORT = 1524))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = dboracle)
    )
  )

EXTPROC_CONNECTION =
 (DESCRIPTION =
  (ADDRESS_LIST =
  (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC)) )
  (CONNECT_DATA = (SID = PLSExtProc) (PRESENTATION = RO))
 )

LISTENER_DBORACLE =
  (ADDRESS = (PROTOCOL = TCP)(HOST = OMAR-PC.TELETIC.DZ)(PORT = 1524))


and then excuted this :

create or replace library math_lib AS 'C:\app\Administrateur\product\11.2.0\dbhome_1\BIN\external-db-func.dll';

/
create or replace function add_number(a1 number,a2 in number) RETURN number 
AS EXTERNAL LIBRARY math_lib NAME "add" LANGUAGE C;

/

DECLARE

begin

DBMS_OUTPUT.PUT(', '||add_number(1,2));
end;


/


but i got an error :
Rapport d'erreur -
ORA-06520: PL/SQL : Erreur pendant le chargement de la bibliothèque externe
ORA-06522: Unable to load DLL
ORA-06512: à "DT_VOUCHER_USER.ADD_NUMBER", ligne 1
ORA-06512: à ligne 5
06520. 00000 -  "PL/SQL: Error loading external library"
*Cause:    An error was detected by PL/SQL trying to load the external
           library dynamically.
*Action:   Check the stacked error (if any) for more details.


please help me i'm clueless.

and Chris said...

Most importantly:

Is the DDL on YOUR machine, or the DATABASE server?

Ensure you've loaded it on the server. If you have, MOS note 68055.1 gives the following advice for resolving this:

1. Find path where the DLL is located and then recreate the Library
to ensure the entire path plus filename is used when creating.

2. If step 1 fails, move the file to the C:\ root drive and then once again
recreate the Library to point to 'C:\<filename>.DLL'. This will help eliminate
the potential of the incorrect/misspelled directory from being used.

3. If the above steps fail, make sure the DLL is locate on the same machine
as the database. Many times a user will place the DLL on the client machine
instead of on the server.
If the first two steps fail, step 3 will usually resolve the problem.

4. Ensure that the DLL entrypoint that is used is spelled correctly.
Verify that you can call the DLL function from a main C program
before calling it as an external procedure.


Is this answer out of date? If it is, please let us know via a Comment

More to Explore

PL/SQL demos

Check out more PL/SQL tutorials on our LiveSQL tool.

PL/SQL docs

PL/SQL reference manual from the Oracle documentation library