Solved

ADO 2.5 to call Oracle Stored Procedures

Posted on 2000-03-28
9
305 Views
Last Modified: 2010-05-02
Hi,

I'm not sure this is in the right category, but I'm trying to call stored procedures using MS ADO 2.5, which apparently it can do it with ease. This appears not to be the case. I know little nothing about Oracle, but have created a Package and a Procedure to return a Ref Cursor. This should be returned to the Visual Basic layer as a recordset. When I run the following code in VB, it always gives me an error on the 'Execute' line, saying that "invalid SQL". This can surely not be the case as the stored proc has been tested in Oracle.

The following is the VB code to call the stored proc:


'**************************************
Option Explicit

Private Const CONNECTION_STRING  As String = "Data Source=MSOSM3;Password = OSMO; User ID = OSMO"

Private mstrSQL As String
Private mcmdStoredProc As ADODB.Command
Private mrsReturn As ADODB.Recordset
Private mprmParameter  As ADODB.Parameter
Private mADOConnection As ADODB.Connection

Public Sub Init()

'Initialise ADO variables
Set mcmdStoredProc = New ADODB.Command
Set mrsReturn = New ADODB.Recordset
Set mprmParameter = New ADODB.Parameter
Set mADOConnection = New ADODB.Connection

'Set the connection string and connect
With mADOConnection
  .ConnectionString = CONNECTION_STRING
  .ConnectionTimeout = 10
  .Open
End With

End Sub


Public Function getDivisions() As ADODB.Recordset

On Error GoTo ErrorHandler

mstrSQL = "NIKTEST.getDivisions"

With mcmdStoredProc
  .ActiveConnection = mADOConnection
  .CommandType = adCmdText
  .CommandText = mstrSQL
End With

'Set mrsReturn = mcmdStoredProc.Execute
mcmdStoredProc.Execute


Exit Function

ErrorHandler:
  MsgBox Err.Description
  Resume Next

End Function

'**************************************

Can anyone let me know whether they've managed to get this particular method of calling stored procs to work with the new ADO 2.5, or maybe it just doesn't work (wouldn't surprise me!).
Thanks, Nik.
0
Comment
Question by:NikWhitfield
  • 4
  • 3
  • 2
9 Comments
 
LVL 28

Expert Comment

by:AzraSound
ID: 2663405
what parameters are you passing to your stored procedure?
0
 

Author Comment

by:NikWhitfield
ID: 2663427
The stored procedure doesn't take any parameters, apart from the 'in out' ref cursor which is added implicitely by ADO, I believe.
0
 
LVL 14

Accepted Solution

by:
wsh2 earned 150 total points
ID: 2663435
Change your

..CommandType = adCmdText

to

..CommandType = adCmdStoredProc
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

Author Comment

by:NikWhitfield
ID: 2663437
By the way, I have tried it using a stored proc which does take some input, e.g. a varchar, but the result is always the same. If I change the name of the package and procedure in the code to something which doesn't exist, the same error occurs. This is strange, as it's almost as if it can't see the package / procedure, but this DB doesn't use synonyms. Hmmm.
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 2663504
geez its late I didnt even see that
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 2663523
dont know if you just didnt include it in your snippet but you should also destroy the Command object when youre done:
Set mcmdStoredProc = Nothing

0
 

Author Comment

by:NikWhitfield
ID: 2663670
CommandType property - schoolboy stuff! Good one!
I also found the DSN was using the 1997 version of Microsoft ODBC for Oracle which didn't help.

OK. This question was for a fair few points, so a tiny extra bit of info and I'd be grateful.

When I get recordsets back, I can't get a recordcount back, no matter which cursor type I set the recordset to. I read somewhere that Oracle doesn't support it, but I've seen it done using ADO 2.1. Can it be done with 2.5?
0
 

Author Comment

by:NikWhitfield
ID: 2663769
It's OK, just need to set the .cursorlocation to aduseclient. Mighth have performance implications, but it'll do for now. Thanks for the help chaps / lasses.
0
 
LVL 14

Expert Comment

by:wsh2
ID: 2663785
Not that it is conclusive, but I can't find anything that states the  RecordCount property with Oracle DBs will not work with ADO.

As to the ADO Cursor types that do support the RecordCount property, please read the following MSDN excerpt..

-------------------------------------
The cursor type of the Recordset object affects whether the number of records can be determined. The RecordCount property will return -1 for a forward-only cursor, the actual count for a static or keyset cursor, and either -1 or the actual count, depending on the data source, for a dynamic cursor.
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Pull multiple cvs files into one access table 28 69
VB6 Compile Compatibility Issue 4 115
Sorting multiple rows and columns, and count duplicates in Excel 2013 4 87
vbModal 12 57
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question