Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > Pro VB 6
|
Pro VB 6 For advanced Visual Basic coders working in version 6 (not .NET). Beginning-level questions will be redirected to other forums, including Beginning VB 6.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro VB 6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 21st, 2009, 02:47 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default Executing Oracle Stored Procedure

I have an Oracle stored procedure (see below) which I can execute successfully from the simple interface from Oracle called SQL*Plus.

Trying to run this procedure from VB6 is giving me trouble, though.

I have:
Code:
    On Error GoTo Er
 
' Open Connection
Dim c As New ADODB.Connection
  c.Provider = "MSDASQL"
  c.ConnectionString = "DRIVER={Microsoft ODBC for Oracle};" & _
                       "SERVER=DIS;" & _
                       "UID=xxx;" & _
                       "PASSWORD=xxxxxxxx;"
  c.ConnectionTimeout = 10
  c.Open
 
 
' Create a Command obj. & set .CommandText 
' to the name of the stored procedure.
Dim cmd As New ADODB.Command
  cmd.CommandType = adCmdStoredProc
  cmd.CommandText = "SEND_EMAIL"
 
' Create, fill-in, then add a param/arg to the Cmd Obj., 
' in order.
Dim prm As ADODB.Parameter
Set prm = New ADODB.Parameter:  prm.Type = adVarChar
                              prm.Direction = adParamInput
                              prm.Name = "sender_name"
                              prm.Value = ""
                              prm.Size = Len(prm.Value) + 1
                              cmd.Parameters.Append prm
 
Set prm = New ADODB.Parameter:  prm.Type = adVarChar
                              prm.Direction = adParamInput
                              prm.Name = "sender"
                              prm.Value = "[email protected]"
                              prm.Size = Len(prm.Value)
                              cmd.Parameters.Append prm
 
Set prm = New ADODB.Parameter:  prm.Type = adVarChar
                              prm.Direction = adParamInput
                              prm.Name = "recipient_name"
                              prm.Value = "" 
                              prm.Size = Len(prm.Value) + 1
                              cmd.Parameters.Append prm
 
Set prm = New ADODB.Parameter:  prm.Type = adVarChar
                              prm.Direction = adParamInput
                              prm.Name = "recipient"
                              prm.Value = "[email protected]"
                              prm.Size = Len(prm.Value)
                              cmd.Parameters.Append prm
 
Set prm = New ADODB.Parameter:  prm.Type = adVarChar
                              prm.Direction = adParamInput
                              prm.Name = "copy_to_name"
                              prm.Value = ""
                              prm.Size = Len(prm.Value) + 1
                              cmd.Parameters.Append prm
 
Set prm = New ADODB.Parameter:  prm.Type = adVarChar
                              prm.Direction = adParamInput
                              prm.Name = "copy_to"
                              prm.Value = ""
                              prm.Size = Len(prm.Value) + 1
                              cmd.Parameters.Append prm
 
Set prm = New ADODB.Parameter:  prm.Type = adVarChar
                              prm.Direction = adParamInput
                              prm.Name = "subject"
                              prm.Value = "Test Sending"
                              prm.Size = Len(prm.Value) + 1
                              cmd.Parameters.Append prm
 
Set prm = New ADODB.Parameter:  prm.Type = adVarChar
                              prm.Direction = adParamInput
                              prm.Name = "message"
                              prm.Value = "Message Body"
                              prm.Size = Len(prm.Value)
                              cmd.Parameters.Append prm
' .Execute the Command object.
cmd.Execute
 
Rs: Exit Sub
 
Er:  . . .
The form of the stored procedure is:
Code:
TEXTPROCEDURE "SEND_EMAIL" 
( sender_name    IN VARCHAR2, 
sender         IN VARCHAR2, 
recipient_name IN VARCHAR2, 
recipient      IN VARCHAR2, 
copy_to_name   IN VARCHAR2, 
copy_to        IN VARCHAR2, 
subject        IN VARCHAR2, 
message        IN VARCHAR2)
The errors are:
Code:
c.Errors.Count:          1 
c.Errors(0).NativeError: 0
c.Errors(0).Number:      0
c.Errors(0).Description: [Microsoft][ODBC Driver Manager] 
                   Driver's SQLSetConnectAttr failed.
err.Number:      3709
err.Source:      ADODB.Command 
err.Description: The connection cannot be used to perform 
                this operation.  It is either closed or 
                invalid in this context.
c.State:         1 (adStateOpen)
What can this mean?
 
Old April 21st, 2009, 06:12 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

hello. Problems with permisions?
__________________
HTH

Gonzalo


================================================== =========
Read this if you want to know how to get a correct reply for your question.
(Took that from Doug signature and he Took that from Peter profile)
================================================== =========
My programs achieved a new certification :
WORKS ON MY MACHINE
================================================== =========
I know that CVS was evil, and now i got the
proof.
================================================== =========
 
Old April 21st, 2009, 08:44 PM
Friend of Wrox
 
Join Date: Sep 2005
Posts: 812
Thanks: 1
Thanked 53 Times in 49 Posts
Default

Hi Brian

I feel the connection is not assigned to the command object. Can you try the following:

Code:
Dim cmd As New ADODB.Command
  cmd.ActiveConnection = c
  cmd.CommandType = adCmdStoredProc
  cmd.CommandText = "SEND_EMAIL"
Cheers
Shasur
__________________
C# Code Snippets (http://www.dotnetdud.blogspot.com)

VBA Tips & Tricks (http://www.vbadud.blogspot.com)





Similar Threads
Thread Thread Starter Forum Replies Last Post
Executing an UPDATE Stored Procedure ashg657 Access VBA 1 June 9th, 2006 06:29 AM
Create and executing an oracle stored procedure Venstar Oracle 1 January 10th, 2006 05:10 AM
Executing a stored procedure from ASP tlbacon527 Classic ASP Databases 2 January 23rd, 2004 03:50 PM
Executing a Stored Procedure using ASP. treadmill Classic ASP Databases 3 July 24th, 2003 04:21 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.