Solved

ADO 2.5 to call Oracle Stored Procedures

Posted on 2000-03-28
9
302 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
 

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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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…
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…
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…

746 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now