Hi. I have this stored procedure: 
I used two temporary tables and then a cursor that joins those tables instead
of only using a join with all the tables, because some of them are really big
(hjli0202 65 columns and over 2.5 millions of records, clli0806 28 columns and over 4.7 millions of records)
and the initial full select took too much executing time. Using temporary tables
partitioning the selects and then joining them in a cursor reduced a lot of time.
The problem i'm facing now is when i execute the procedure for a second time from a
C#.net application, i get a SQL0913 error (Row or object CERECFLO in QTEMP type *FILE in use).
I found out that while the cursor is in use the temporary tables won't be dropped from QTEMP
(if a close the cursor after openning it i get no error, but obviously no data either).
I tried to copy the data from cursor datos to another one allowing me returning the new cursor to caller and closing cursor datos)
but i couldn't find how to do that. Is there a way to do this? Could you give me another possible solution?
i'll appreciate a lot any useful help.
I'm using IBM.Data.DB2.iSeries driver to connect from C# to DB2, and a iDB2DataReader to work
with the result set returned from the stored procedure (i close the iDB2DataReader after using it in the C# code,
but it doesn't close the cursor).

PHP Code:
create procedure consulta_recibos_flota_cobertura_siniestro
(in @tipide char, in @cedreg char(9), in @numpla varchar(8),
in @fecsin varchar(8))
dynamic result sets 1
language sql
modifies sql data
begin
declare sqlStm varchar(5000);
declare datos cursor with return to caller for
select vig.ramo, vig.poliza, vig.numrec, vig.stsfin
from qtemp/cerecvig vig
inner join qtemp/cerecflo flo on flo.ramo = vig.ramo and
flo.poliza = vig.poliza and
flo.numrec = vig.numrec;
set sqlStm= 'declare global temporary table cerecflo as
(select distinct c08.ramo, c08.poliza, c08.numrec
from clli0806 c08
inner join clli0710 c07 on
c07.ramo = c08.ramo and
c07.poliza = c08.poliza and
c07.cerveh = c08.cerveh
where c07.numpla = ''' || @numpla || ''' and
c07.tipide = ''' || @tipide || ''' and
c07.cedben = ''' || @cedreg || ''') with data with replace';
prepare qry from sqlStm;
execute qry;
set sqlStm= 'declare global temporary table cerecvig as
(select h02.ramo, h02.poliza, h02.numrec, h02.stsfin
from hjli0202 h02
where h02.ramo = 31 and h02.stssit = ''1'' and
h02.cdoper in (1, 4, 20) and
(
((h02.anodes*10000)+(h02.mesdes*100)+h02.diades) <=
' || @fecsin || '
and
((h02.anohas*10000)+(h02.meshas*100)+h02.diahas) >=
' || @fecsin || '
) ) with data with replace';
prepare qry from sqlStm;
execute qry;
open datos;
end;
of only using a join with all the tables, because some of them are really big
(hjli0202 65 columns and over 2.5 millions of records, clli0806 28 columns and over 4.7 millions of records)
and the initial full select took too much executing time. Using temporary tables
partitioning the selects and then joining them in a cursor reduced a lot of time.
The problem i'm facing now is when i execute the procedure for a second time from a
C#.net application, i get a SQL0913 error (Row or object CERECFLO in QTEMP type *FILE in use).
I found out that while the cursor is in use the temporary tables won't be dropped from QTEMP
(if a close the cursor after openning it i get no error, but obviously no data either).
I tried to copy the data from cursor datos to another one allowing me returning the new cursor to caller and closing cursor datos)
but i couldn't find how to do that. Is there a way to do this? Could you give me another possible solution?
i'll appreciate a lot any useful help.
I'm using IBM.Data.DB2.iSeries driver to connect from C# to DB2, and a iDB2DataReader to work
with the result set returned from the stored procedure (i close the iDB2DataReader after using it in the C# code,
but it doesn't close the cursor).




Comment