wlevy
asked on
VBScript calling SQL Server stored procedure with OUTPUT parameter
Hi - I have a VBS file that I use to execute a SQL Server stored procedure, but I want to enhance it by retrieving a "Status" indicator when the stored proc ends. I don't think I can use a RETURN value in the stored proc so I added an OUTPUT parameter.
The stored proc has two input parameters and one output parameter. When it had just the two input parameters I called in from VBS like this:
NOTE: cn is an ADODB connection object.
cn.Execute("MyProc 'N', 1)
That works fine. With the new output parameter (@RETURN_STATUS INTEGER OUTPUT), I am trying to call the stored proc like this:
Dim RetVal
RetVal = 99
cn.Execute("MyProc 'N', 1, @RETURN_STATUS = " & RetVal & " OUTPUT")
I get the following error message:
[Microsoft][ODBC SQL Server Driver][SQL Server]Cannot use the OUTPUT option when passing a constant to a stored procedure.
NOTE: I tested the stored proc in SQL Server like this:
declare @rtn integer
exec MyProc 'N',1,@RETURN_STATUS = @rtn OUTPUT
print 'Return value = ' + cast(@rtn as varchar)
Can anyone tell me how I can call the stored proc using the connection object and get the value of the output parameter?
Do I have to use a command object?
Thanks!
The stored proc has two input parameters and one output parameter. When it had just the two input parameters I called in from VBS like this:
NOTE: cn is an ADODB connection object.
cn.Execute("MyProc 'N', 1)
That works fine. With the new output parameter (@RETURN_STATUS INTEGER OUTPUT), I am trying to call the stored proc like this:
Dim RetVal
RetVal = 99
cn.Execute("MyProc 'N', 1, @RETURN_STATUS = " & RetVal & " OUTPUT")
I get the following error message:
[Microsoft][ODBC SQL Server Driver][SQL Server]Cannot use the OUTPUT option when passing a constant to a stored procedure.
NOTE: I tested the stored proc in SQL Server like this:
declare @rtn integer
exec MyProc 'N',1,@RETURN_STATUS = @rtn OUTPUT
print 'Return value = ' + cast(@rtn as varchar)
Can anyone tell me how I can call the stored proc using the connection object and get the value of the output parameter?
Do I have to use a command object?
Thanks!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Great!
Hello,
I am also facing the same issue as mentioned by Wlevy and the below suggested link was not working.
http://authors.aspalliance.com/stevesmith/articles/sprocs.asp
Can you please provide solution for this.
Stored Procedure:
create or replace procedure sproc_oraint02_send_email_ test
(
ip_event IN EMAIL_DETAIL.EMAIL_EVENT%T YPE,
ip_sub_event IN EMAIL_dETAIL.EMAIL_SUB_EVE NT%TYPE,
---- ip_file_dir IN VARCHAR2,
---- ip_file_name IN VARCHAR2,
op_error OUT VARCHAR2
)
IS
lv_attach varchar2(4000);
PROCEDURE_NAME VARCHAR2(40) := 'sproc_oraint02_send_email _test';
lv_string VARCHAR2(32000);
email_detail_buf email_detail%ROWTYPE;
lv_num_files PLS_INTEGER; -- IT_TASK_XXXXX
lv_file_name VARCHAR2(200); -- IT_TASK_32526
user_exception EXCEPTION;
BEGIN
BEGIN
SELECT *
into email_detail_buf
from email_detail
where email_event = ip_event
and email_Sub_Event = ip_sub_event;
EXCEPTION
WHEN NO_DATA_FOUND THEN
RAISE user_exception;
END;
lv_string := '(/bin/printf "%s\n" "'||email_detail_buf.body_ line_1||'" " " "'||email_detail_buf.body_ line_2||'" "'||email_detail_buf.body_ line_3;
lv_string := lv_string||'" "'||email_detail_buf.body_ line_4||'" "'||email_detail_buf.body_ line_5||'" "'||email_detail_buf.body_ line_6||'" " " "';
lv_string := lv_string||email_detail_bu f.footer_1 ||'" "'||email_detail_buf.foote r_2||'" "'||email_detail_buf.foote r_3||'";)' ;
dbms_output.put_line(lv_st ring);
/* IT_TASK_32526 Start */
---IF email_detail_buf.ATTACH_YN ='Y' THEN
-- lv_attach := ' -a "'||ip_file_dir||'/'||ip_f ile_name|| '"';--IT_T ASK_34647
/*IT_TASK_34791 Start */
-- lv_num_files := orautils.num_entries(ip_fi le_name);
--FOR i in 1 .. lv_num_files LOOP
--- lv_file_name := orautils.ENTRY(i,ip_file_n ame);
--lv_attach := lv_attach||' -a "'||ip_file_dir||'/'||lv_f ile_name|| '"';--IT_T ASK_34647
-- END LOOP;
/*IT_TASK_34791 End */
-- END IF;
/* IT_TASK_32526 End */
lv_string := lv_string||' | /bin/mailx -s "'||email_detail_buf.subje ct||'" "'||email_detail_buf.email _to||'"';
dbms_output.put_line(lv_st ring);
--sample command
--(/usr/bin/printf "%s\n" "Hi ," " " "Please find the attached output file of Silent Failure Logging." "" "" "" "" " " "" "Regards , " "CGI";) | /bin/mailx -s " Paycash Audit Log" -a "/data_uk/ukphxdv1/progres s/log/test _ftp_goldm ine.log" "vipin.nambiar@cgi.com,vip innambiar7 776@gmail. com"
ORAINT02.SPROC_ORAINT02_HO ST_COMMAND (
lv_string
);
EXCEPTION
WHEN USER_EXCEPTION THEN
op_error := 'Configuration Missing in EMAIL_DETAIL , Please Check ';
WHEN OTHERS THEN
op_error := 'send mail failure ';
dbms_output.put_line('send mail failure');
---op_error := Oraerror.fatal_error(
-- PACKAGE_NAME,
--PROCEDURE_NAME,
--'0',
-- SQLCODE
--- );
END sproc_oraint02_send_email_ test;
Executed below code in Oracle SQL Developer it worked fine.
--- Calling the procedure---
declare
ip_event varchar2(20) :='44720' ;
ip_sub_event varchar2(20) :='1';
op_error varchar2(20);
begin
sproc_oraint02_send_email_ test(ip_ev ent,ip_sub _event,op_ error);
end;
Vb Script Code I am trying:
conStr="Driver={Microsoft ODBC for Oracle}; " &"CONNECTSTRING=(DESCRIPTI ON=" &"(ADDRESS=(PROTOCOL=TCP)" & "(HOST="& HOST &")(PORT="& PORT &"))" & "(CONNECT_DATA=(SERVICE_NA ME="& SERVICENAME &"))); uid="& USER &";pwd="& PASSWORD &";"
Set cn = CreateObject("ADODB.Connec tion")
cn.Open conStr
Set cmdObj=createobject("adodb .command")
With cmdObj
.activeconnection=cn
.commandtype=1
.commandtext="sproc_oraint 02_send_em ail_test"
End with
param1=44721
param2=1
cn.Execute("CALL sproc_oraint02_send_email_ test('" & param1 & "','" & param2 & "',:op_error)")
I am getitng below error
"ORA-01008: not all variables bound"
Please check the attached file for the issue.
EmailSPIssue.JPG
I am also facing the same issue as mentioned by Wlevy and the below suggested link was not working.
http://authors.aspalliance.com/stevesmith/articles/sprocs.asp
Can you please provide solution for this.
Stored Procedure:
create or replace procedure sproc_oraint02_send_email_
(
ip_event IN EMAIL_DETAIL.EMAIL_EVENT%T
ip_sub_event IN EMAIL_dETAIL.EMAIL_SUB_EVE
---- ip_file_dir IN VARCHAR2,
---- ip_file_name IN VARCHAR2,
op_error OUT VARCHAR2
)
IS
lv_attach varchar2(4000);
PROCEDURE_NAME VARCHAR2(40) := 'sproc_oraint02_send_email
lv_string VARCHAR2(32000);
email_detail_buf email_detail%ROWTYPE;
lv_num_files PLS_INTEGER; -- IT_TASK_XXXXX
lv_file_name VARCHAR2(200); -- IT_TASK_32526
user_exception EXCEPTION;
BEGIN
BEGIN
SELECT *
into email_detail_buf
from email_detail
where email_event = ip_event
and email_Sub_Event = ip_sub_event;
EXCEPTION
WHEN NO_DATA_FOUND THEN
RAISE user_exception;
END;
lv_string := '(/bin/printf "%s\n" "'||email_detail_buf.body_
lv_string := lv_string||'" "'||email_detail_buf.body_
lv_string := lv_string||email_detail_bu
dbms_output.put_line(lv_st
/* IT_TASK_32526 Start */
---IF email_detail_buf.ATTACH_YN
-- lv_attach := ' -a "'||ip_file_dir||'/'||ip_f
/*IT_TASK_34791 Start */
-- lv_num_files := orautils.num_entries(ip_fi
--FOR i in 1 .. lv_num_files LOOP
--- lv_file_name := orautils.ENTRY(i,ip_file_n
--lv_attach := lv_attach||' -a "'||ip_file_dir||'/'||lv_f
-- END LOOP;
/*IT_TASK_34791 End */
-- END IF;
/* IT_TASK_32526 End */
lv_string := lv_string||' | /bin/mailx -s "'||email_detail_buf.subje
dbms_output.put_line(lv_st
--sample command
--(/usr/bin/printf "%s\n" "Hi ," " " "Please find the attached output file of Silent Failure Logging." "" "" "" "" " " "" "Regards , " "CGI";) | /bin/mailx -s " Paycash Audit Log" -a "/data_uk/ukphxdv1/progres
ORAINT02.SPROC_ORAINT02_HO
lv_string
);
EXCEPTION
WHEN USER_EXCEPTION THEN
op_error := 'Configuration Missing in EMAIL_DETAIL , Please Check ';
WHEN OTHERS THEN
op_error := 'send mail failure ';
dbms_output.put_line('send
---op_error := Oraerror.fatal_error(
-- PACKAGE_NAME,
--PROCEDURE_NAME,
--'0',
-- SQLCODE
--- );
END sproc_oraint02_send_email_
Executed below code in Oracle SQL Developer it worked fine.
--- Calling the procedure---
declare
ip_event varchar2(20) :='44720' ;
ip_sub_event varchar2(20) :='1';
op_error varchar2(20);
begin
sproc_oraint02_send_email_
end;
Vb Script Code I am trying:
conStr="Driver={Microsoft ODBC for Oracle}; " &"CONNECTSTRING=(DESCRIPTI
Set cn = CreateObject("ADODB.Connec
cn.Open conStr
Set cmdObj=createobject("adodb
With cmdObj
.activeconnection=cn
.commandtype=1
.commandtext="sproc_oraint
End with
param1=44721
param2=1
cn.Execute("CALL sproc_oraint02_send_email_
I am getitng below error
"ORA-01008: not all variables bound"
Please check the attached file for the issue.
EmailSPIssue.JPG
ASKER