Link to home
Start Free TrialLog in
Avatar of colindow
colindow

asked on

Returning recordset to VB6 using cmd object and oracle sys_refcursor

I am trying to return a recordset to VB6 from an oracle procedure (in a package using a sys_refcursor -oracle 10g). I am using a connection string based on Provider=MSDAORA.

The procedure has two parameters an IN id and an OUT sys_refcursor. This is the header of the proc
procedure get_usertest1 (in_acct_id in useraccounts.id%type, mycursor out sys_refcursor)
this returns a single record sys_refcursor based on the id in.

e.g. Select * FROM table where ID=in_acct_id;

I would have thought the code to do this should look like this
    szCmd = "DATA_TOOLS.GET_USERTest1"
   
    Set rs = New ADODB.Recordset
    Set cmd = New ADODB.Command
   
    With cmd
       
        .ActiveConnection = mconnoracle
        .CommandText = szCmd
        .CommandType = adCmdStoredProc
        .Parameters.Append .CreateParameter(, adNumeric, adParamInput, , plngId)
           
    End With
   
    Set rs = cmd.Execute()

but this gives me an error about parameters (wrong number or types of arguments in call to 'GET_USERTEST1') - my understanding from reading various items on the web is that its not necessary to add a parameter in the VB cmd object for the returning recordset.

However If I change the command text to embed the ID in the commands text and make the commandtype adCmdText then the code  executes successfully. I'm a bit nervous about using this as I'm not sure why this way works. Should the first method work and if so what have I done wrong?

This works:-
    szCmd = "begin DATA_TOOLS.GET_USERTest1(7370); end;"
   
    Set rs = New ADODB.Recordset
    Set cmd = New ADODB.Command
   
    With cmd
       
        .ActiveConnection = mconnoracle
        .CommandText = szCmd
        .CommandType = adCmdText
                   
    End With
   
    Set rs = cmd.Execute()
ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of colindow
colindow

ASKER

many thanks for your prompt response

COuldnt get the MSDAORA to work but the OraOLEDB.Oracle with the PLSQLRSet=1 extended properties dit the trick . Originally my connection string was "Driver={Microsoft ODBC for Oracle}" but none of my attempts to retunr a cursor worked. Do you know of any good references sies where I can read a bit about the differences in the providers behaviour. I should really find out more before I push out the existing code with a new provider string!

>Do you know of any good references sies where I can read a bit about the differences in the providers behaviour
no, as each one cooks it own meal... MSDAORA is what microsoft made as provider to make the linked servers in sql server to work
the ms odbc for oracle is to use the odbc driver instead of oledb.

only the oraoledb is from oracle, so only those can really know how to internally do the internal stuff efficiently...
the only way is to test, sad to say.
note that 10 years ago, I had a terrible choice to do:
* use the oracle odbc driver, which was slow
* use the ms oracle odbc driver, which had a bug
* change my nice code to terrible code

Thats good to know as we currently have an old SQL server 6.5 database and our app interacts with our oracle 10g rack. Hope to upgrade SQL server pretty soon so the linked server stuff may soon be of interest - but thats another story....

Thanks again.