Solved

ADO 2.5 to call Oracle Stored Procedures

Posted on 2000-03-28
9
304 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
Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

770 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