Solved

ADO 2.5 to call Oracle Stored Procedures

Posted on 2000-03-28
9
303 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

895 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

15 Experts available now in Live!

Get 1:1 Help Now