How to call an Oracle Stored Procedure that returns REF CURSORS using ADO in C++
I want to call this oracle stored procedures "vi_list_print" :
PACKAGE BODY VNM_TEST_PKG
IS
--return list of masters
function vi_list(p_address in varchar2)
return vnm_masters_c
is
l_cursor vnm_masters_c;
begin
open l_cursor for
select *
from VNM_MASTERS
where adresse like (p_address);
return l_cursor;
end;
procedure vi_list_print(p_address in varchar2)
is
l_cursor vnm_masters_c;
l_record vnm_masters%rowtype;
begin
l_cursor:=vi_list(p_address);
loop
fetch l_cursor into l_record;
exit when l_cursor%notfound;
dbms_output.put_line(
l_record.adresse
|| chr(9)
||l_record.sort_key_title
);
end loop;
end;
END;
I tried it with SQL Navigator and it's work perfectly. But when I try
to call it by Visual C++ it doesn't work, when I try to access the
recordset returned, it raise an exeption because the recordset seems to
be close.
Here's the C++ code :
void CallStoredProcedure()
{
try
{
_ConnectionPtr m_pConn;
_RecordsetPtr pRecordset;
_CommandPtr pCommand;
_ParameterPtr pParam1, pParam2;
_variant_t vt;
vt.SetString("VI34890000");
m_pConn.CreateInstance (__uuidof (Connection));
pCommand.CreateInstance (__uuidof (Command));
m_pConn->Open (
_bstr_t ("Provider=MSDAORA.1;PLSQLRSet=1;Data Source=colt"),
_bstr_t ("voutenum"), _bstr_t ("voutenum"), adModeUnknown);
pCommand->ActiveConnection = m_pConn;
pParam1 = pCommand->CreateParameter( _bstr_t ("@p_address"),
adVarChar, adParamInput, 2000,( VARIANT ) vt);
pCommand->Parameters->Append(pParam1);
pCommand->CommandText = "{CALL VNM_TEST_PKG.vi_list_print(?)}";
pRecordset.CreateInstance (__uuidof (Recordset));
pRecordset = pCommand->Execute(NULL, NULL, adCmdStoredProc |
adCmdUnspecified );
//Check the recordset state
if(pRecordset->GetState() == 0)
MessageBox("Recordset closed");
//Raise exeption !!!! because recordset close
pRecordset->MoveFirst();
}catch(_com_error & e)
{
_bstr_t bstrSource(e.Source());
_bstr_t bstrDescription(e.Description());
CString message;
message.Format("\n Source : %s \n Description : %s
\n",(LPCSTR)bstrSource,(LPCSTR)bstrDescription);
MessageBox(message);
}
CoUninitialize();
}
The messagebox with the message "Recordset closed" appears and the
exeption "Source : ADODB.Recordset Description : Operation is not
allowed when the object is closed." is raised.
Is someone can help me ?
Thanks

