?
Solved

ADO 2.5 to call Oracle Stored Procedures

Posted on 2000-03-28
9
Medium Priority
?
313 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 600 total points
ID: 2663435
Change your

..CommandType = adCmdText

to

..CommandType = adCmdStoredProc
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
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…
Suggested Courses
Course of the Month14 days, 1 hour left to enroll

801 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