• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3536
  • Last Modified:

ORA-28576: lost RPC connection to external procedure agent

Hi All,

Hope someone can offer some advise here. I'm attempting to develop a routine in C (as a shared library) and then call this from PL/SQL. The code compiles (via gcc) and links (via ld) fine but when called from PL/SQL I get error "ORA-28576: lost RPC connection to external procedure agent"

I have narrowed the problem as outlined in the sample code below. With "i = strlen("ABCDE");" commented in, the routine works normally and in PL/SQL I get a value of 5. When I comment this line out and comment in  "i = strlen(tmp);" then the RPC error results.

I'm at a loss on this so would appreciate any help.

System Information
====================
Redhat Enterprise Linux AS R3
GCC 3.2.3
Oracle 10g 10.1.0.3

Thanks.
C Library
======================================
#include <stdio.h>
int LCS(char *string1, char *string2)
{
       	int i;
        char tmp[6] = "ABCDE";
 
        // i = strlen(tmp); This does not work
	i = strlen("ABCDE"); // This works
        
	return i;
}
 
Oracle Library Declaration
================================
create or replace library lcs_lib as '/oracle/Ora10103/bin/lcs_lib.so';
 
Wrapper
=================================
create or replace function 
lcs_function(p_str1 in varchar2, p_str2 in varchar2)
return pls_integer
as external library lcs_lib name "LCS" language c
parameters(p_str1 STRING, p_str2 STRING, return int);
 
PL/SQL Call
====================================
declare
	res pls_integer;
	v_str1 char(20);
	v_str2 char(20);
	
begin
	v_str1 := 'aa';
	v_str2 := 'aaa';
	res := lcs_function(v_str1, v_str2);
 
	dbms_output.put_line('LCS Output is: ' || res);
end;

Open in new window

0
MichaelOS
Asked:
MichaelOS
  • 3
  • 2
  • 2
1 Solution
 
schwertnerCommented:
This means that the C type doesn't correspond the PL/SQL type.
Try to clarify and possibly change VARCHAR2 with CHAR.
0
 
schwertnerCommented:
Also PL/SQL has a set of character functions. What is the purpose to use
C for this? You have to use C for system programming and for complex
calculations that are either impossible or run slow in PL/SQL.
0
 
MichaelOSAuthor Commented:
Hi,

I'm just testing at the moment. The plan is to rewrite relatively complex approximate string matching algorithms in C  that my company has developed in another language and to use these on the Oracle system. I'm aware that Oracle has character functions but these are not what I need.

I've messed around with the sample code quite a bit so apologies if I have caused some confusion. The 2 string parameters are not being used at the moment. I have changed types to varchar2 without success. The fact that when "i = strlen("ABCDE");" is commented in and "i = strlen(tmp);" commented out the code works would suggest that the parameter types are fine. Reading documentation suggests there can be many causes as to the error I'm encountering. I feel that an exception is occuring in the C routine in the line "i = strlen(tmp);" and this is being raised as a lost RPC connection
0
Free recovery tool for Microsoft Active Directory

Veeam Explorer for Microsoft Active Directory provides fast and reliable object-level recovery for Active Directory from a single-pass, agentless backup or storage snapshot — without the need to restore an entire virtual machine or use third-party tools.

 
garysadlerCommented:
I think you're right that the C library is aborting which causes an unexpected termination of the connection from the PL/SQL wrapper function.  My C is a little rusty, so please forgive me, but what if you try terminating the string with a null (\0)?  Perhaps strlen is giving you fits because it isn't sure about the end of the string it's trying to measure.
0
 
MichaelOSAuthor Commented:
Thanks for the feedback. Yes, I already tried this using the code below and I still receive the error.

char tmp[6];

tmp[0] = 'A';
tmp[1] = 'B';
tmp[2] = 'C';
tmp[3] = 'D';
tmp[4] = 'E';
tmp[5] = '\0';

i = strlen(tmp);

The weird thing is that this code works fine when called in a simple C program
0
 
garysadlerCommented:
Maybe it has to do with the way the compile and link is playing out.  I tried your code on my Linux server and it worked iwthout a hitch, whether using the tmp variable or not.  Here's how I did it:

cc -g -c -fPIC lcs_lib.c

(the following is all on one line)
make -f $ORACLE_HOME/rdbms/demo/demo_rdbms.mk extproc_no_context SHARED_LIBNAME=lcs_lib.so OBJS=lcs_lib.o
0
 
MichaelOSAuthor Commented:
Hi,
Many thanks for the feedback. I was not compiling with the -fPIC option. When I included this, the PL/SQL call worked. I've looked up the -fPIC option does but to be honest I'm not entirely sure how it resolved the issue I was having. Just to add I'm testing this on a Dell PowerEdge 1850 server with 2*64bit Xeon. Thanks again for the assistance.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now