Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Unspecified error while calling a PL/SQL ref cursor from VB using ADO

I have a form in MS Access/vb and I am trying to connect to Oracle Database and call a ref cursor in Oracle PL/SQL procedure using ADO.

I am able to connect successfully, but when I execute the command (when I call the ref cursor) I get a RUNTIME UNSPECIFIED ERROR.

In my procedure p_user_id is an input numeric variable and then there is a ref cursor.

Following is my code (please help me determine what am I missing):


Option Explicit

Public m_adoCnn As New ADODB.Connection
Public m_adoRst As New ADODB.Recordset


Private Sub Command0_Click()


Dim Cn As ADODB.Connection
Dim CP As ADODB.Command
Dim Rs As ADODB.Recordset
Dim Conn As String
Dim SSQL As String
Dim Pr As New ADODB.Parameter

Set CP = New ADODB.Command
Set Cn = New ADODB.Connection

'Connect to Oracele server begin
Conn = "Provider=OraOLEDB.Oracle;Data Source=x;UserID=y; Password=z;PLSQLRset=1;"


With Cn
.ConnectionString = Conn
.CursorLocation = adUseClient
.Open
End With

If Cn.State = adStateOpen Then
MsgBox "Connection successful."
End If

SSQL = "{call test_pkg.test_PROC(?)}"

With CP
.ActiveConnection = Cn
.CommandType = adCmdStoredProc
.CommandText = SSQL

.Parameters.Append .CreateParameter("p_user_id", adNumeric, adParamInput, , 5)

Set Rs = .Execute()

End With


'Connect to Oracle server end


'close connection begin
Cn.Close
Set Cn = Nothing
Set CP = Nothing
'close connection end


End Sub

Private Sub Form_Unload(Cancel As Integer)
m_adoCnn.Close
End Sub
[2017 byte] By [mmk1212] at [2007-11-11 8:16:33]
# 1 Re: Unspecified error while calling a PL/SQL ref cursor from VB using ADO
It seems like if I comment out input parameter from my procedure and then call it from VB it works, but with this

.Parameters.Append .CreateParameter("p_user_id", adNumeric, adParamInput, , 5)

it doesn't work.

Any idea why?
mmk1212 at 2007-11-11 17:25:41 >
# 2 Re: Unspecified error while calling a PL/SQL ref cursor from VB using ADO
It sounds like your parameter doesn't match what is defined in your sp. What does your package definition and sp parameters look like?
pclement at 2007-11-11 17:26:41 >
# 3 Re: Unspecified error while calling a PL/SQL ref cursor from VB using ADO
Thanks Paul,

My pkg.procedure is test_pkg.test_PROC

It has one input parameter p_userid, out parameters p_error_msg, p_error_code and a ref cursor
mmk1212 at 2007-11-11 17:27:50 >
# 4 Re: Unspecified error while calling a PL/SQL ref cursor from VB using ADO
Are the parameters defined properly? For example if you're using adNumeric I'm assuming your parameter is defined as a Number data type in your sp?

Could you post the sp definition from your package?
pclement at 2007-11-11 17:28:44 >
# 5 Re: Unspecified error while calling a PL/SQL ref cursor from VB using ADO
Yes I have made parameters are defined properly and the datatypes match.

This is the procedure spec

(p_skey IN NUMBER,
p_user_id IN NUMBER,
c_get_data OUT c_get_typ)


In VB, it is

.Parameters.Append .CreateParameter("p_skey", adNumeric, adParamInput, , 5)
.Parameters.Append .CreateParameter("p_user_id", adNumeric, adParamInput, , 5)
mmk1212 at 2007-11-11 17:29:43 >
# 6 Re: Unspecified error while calling a PL/SQL ref cursor from VB using ADO
I see two parameters but you only have one placeholder (?) in the call.
pclement at 2007-11-11 17:30:51 >
# 7 Re: Unspecified error while calling a PL/SQL ref cursor from VB using ADO
ok Paul,

I changed it to
SSQL = "{call test_pkg.test_PROC(?,?)}"

and also tried

SSQL = "{test_pkg.test_PROC(?,?)}"

still getting the same error
mmk1212 at 2007-11-11 17:31:55 >
# 8 Re: Unspecified error while calling a PL/SQL ref cursor from VB using ADO
Is your ref cursor c_get_typ defined properly? Maybe you could check your stored proc definition against the example in the below article:

http://www.vbip.com/books/1861003927/chapter_3927_16.asp
pclement at 2007-11-11 17:32:46 >