473,385 Members | 1,356 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Getting Return Value of Stored Procedure

Hello Friends !

I have the Following Code, that Executes a Stored Procedure and Attempt to
read a Returned Integer Value from the StoredProc.
But It gives Error ...

ADODB.Command (0x800A0BB9)
Arguments are of the wrong type, are out of acceptable range, or are in
conflict with one another.
/C4U/DBOutputParameterTest.asp, line 25

Can some one Points Out the Problem ....

REM=============================================== ======================
<BODY>
<%
Const adCmdStoredProc = 4

Dim objConnection, objCommand, objParameter, sSQL

Set objConnection = Server.CreateObject("AdoDB.Connection")
Set objCommand = Server.CreateObject("AdoDB.Command")
Set objParameter = Server.CreateObject("AdoDB.Parameter")

'Dim objParameter 'As AdoDB.Parameter

sSQL = "Execute RegisterMessage '13', 'Accounting', 'Accounts', '24304',
'Hello By Test Message', 'P', '2492331', 'VipulP: The Tester'"

objConnection.Open Session("CONNECTION_STRING")
Set objCommand.ActiveConnection = objConnection
objCommand.CommandText = sSQL
objCommand.CommandType = adCmdStoredProc

Set objParameter = objCommand.CreateParameter("Return", adInteger,
adParamReturnValue,,0)
objCommand.Parameters.Append objParameter
Response.Write "SQL: " & sSQL & "<BR>"
'Response.End()

objCommand.Execute()

IF objConnection.Errors.Count > 0 Then
Response.Write "ERROR:<P>"
Response.Write "Error # " & objConnection.Errors(0).Number & "<BR>"
Response.Write "Error Description: " &
objConnection.Errors(0).Description & "<BR>"
Response.Write "Error Source: " & objConnection.Errors(0).Source & "<BR>"
Else
Response.Write "Generated Message Id: " &
objCommand.Parameters.Item("MsgId").Value & "<P>"
End IF

objCommand.Parameters.Refresh()
For Each objParameter In objCommand.Parameters
Response.Write objParameter.Name & ": " & objParameter.Value & "<BR>"
Next
%>
</BODY>

REM=============================================== ======================

Thanks !
------------------------------
V I P U L P A T H A K
eBot Technosoft Limited,
Indore, (MP), India.
http://www.ebotsoft.com
Jul 19 '05 #1
3 22898
www.adopenstatic.com/faq/800a0bb9step2.asp?

Do you have Option Explicit at the top of your page?

Cheers
Ken

"Vipul Pathak" <vi****@ebotsoft.com> wrote in message
news:Ob**************@TK2MSFTNGP10.phx.gbl...
: Hello Friends !
:
: I have the Following Code, that Executes a Stored Procedure and Attempt to
: read a Returned Integer Value from the StoredProc.
: But It gives Error ...
:
: ADODB.Command (0x800A0BB9)
: Arguments are of the wrong type, are out of acceptable range, or are in
: conflict with one another.
: /C4U/DBOutputParameterTest.asp, line 25
:
: Can some one Points Out the Problem ....
:
: REM=============================================== ======================
: <BODY>
: <%
: Const adCmdStoredProc = 4
:
: Dim objConnection, objCommand, objParameter, sSQL
:
: Set objConnection = Server.CreateObject("AdoDB.Connection")
: Set objCommand = Server.CreateObject("AdoDB.Command")
: Set objParameter = Server.CreateObject("AdoDB.Parameter")
:
: 'Dim objParameter 'As AdoDB.Parameter
:
: sSQL = "Execute RegisterMessage '13', 'Accounting', 'Accounts', '24304',
: 'Hello By Test Message', 'P', '2492331', 'VipulP: The Tester'"
:
: objConnection.Open Session("CONNECTION_STRING")
: Set objCommand.ActiveConnection = objConnection
: objCommand.CommandText = sSQL
: objCommand.CommandType = adCmdStoredProc
:
: Set objParameter = objCommand.CreateParameter("Return", adInteger,
: adParamReturnValue,,0)
: objCommand.Parameters.Append objParameter
: Response.Write "SQL: " & sSQL & "<BR>"
: 'Response.End()
:
: objCommand.Execute()
:
: IF objConnection.Errors.Count > 0 Then
: Response.Write "ERROR:<P>"
: Response.Write "Error # " & objConnection.Errors(0).Number & "<BR>"
: Response.Write "Error Description: " &
: objConnection.Errors(0).Description & "<BR>"
: Response.Write "Error Source: " & objConnection.Errors(0).Source &
"<BR>"
: Else
: Response.Write "Generated Message Id: " &
: objCommand.Parameters.Item("MsgId").Value & "<P>"
: End IF
:
: objCommand.Parameters.Refresh()
: For Each objParameter In objCommand.Parameters
: Response.Write objParameter.Name & ": " & objParameter.Value & "<BR>"
: Next
: %>
: </BODY>
:
: REM=============================================== ======================
:
: Thanks !
:
:
: ------------------------------
: V I P U L P A T H A K
: eBot Technosoft Limited,
: Indore, (MP), India.
: http://www.ebotsoft.com
:
:
Jul 19 '05 #2
I personally just use:

Set rsWhatever = objADO.Execute "EXEC sp_SomeStoredProc arg1, arg2"
sReturnValueFromStoredProc = rs.Fields.Item(0).Value
rsWhatever.Close
Set rsWhatever = Nothing

Ray at work

"Vipul Pathak" <vi****@ebotsoft.com> wrote in message
news:Ob**************@TK2MSFTNGP10.phx.gbl...
Hello Friends !

I have the Following Code, that Executes a Stored Procedure and Attempt to
read a Returned Integer Value from the StoredProc.
But It gives Error ...

ADODB.Command (0x800A0BB9)
Arguments are of the wrong type, are out of acceptable range, or are in
conflict with one another.
/C4U/DBOutputParameterTest.asp, line 25

Can some one Points Out the Problem ....

REM=============================================== ======================

Jul 19 '05 #3
Vipul Pathak wrote:
I have the Following Code, that Executes a Stored Procedure and
Attempt to read a Returned Integer Value from the StoredProc.
Good! It is far better to return a single value as a parameter rather than
using a bulky recordset.

REM=============================================== ====================== <BODY>
<%
Const adCmdStoredProc = 4

Dim objConnection, objCommand, objParameter, sSQL
:-) Save yourself some typing - use short object names:
dim cn,cmd,param

These variable names have become almost standard among developers.


Set objConnection = Server.CreateObject("AdoDB.Connection")
Set objCommand = Server.CreateObject("AdoDB.Command")
Set objParameter = Server.CreateObject("AdoDB.Parameter")

'Dim objParameter 'As AdoDB.Parameter

sSQL = "Execute RegisterMessage '13', 'Accounting', 'Accounts',
'24304', 'Hello By Test Message', 'P', '2492331', 'VipulP: The
Tester'"

:-) No, no, no, no, no! You are using adCmdStoredProc, not adCmdText! That
means you need to supply the NAME of the procedure for the CommandText
property! Just the name!

objCommand.CommandText = "RegisterMessage"
objConnection.Open Session("CONNECTION_STRING")
Set objCommand.ActiveConnection = objConnection
objCommand.CommandText = sSQL
objCommand.CommandType = adCmdStoredProc

Set objParameter = objCommand.CreateParameter("Return", adInteger,
adParamReturnValue,,0)
objCommand.Parameters.Append objParameter
Good start. Now you need to create and append the rest of the parameters
collection! And set their values. This can be tricky, but you can make the
task easier by using one of the stored procedure parameter code generators
out there. I've written one myself. It's available at
http://www.thrasherwebdesign.com/ind...asp&c=&a=clear
objCommand.Execute()
No parentheses needed. You should tell the Command that it does not need to
create a recordset behind the scenes:
const adExecNoRecords = &H00000080
objCommand.Execute ,,adExecNoRecords

IF objConnection.Errors.Count > 0 Then
Response.Write "ERROR:<P>"
Response.Write "Error # " & objConnection.Errors(0).Number & "<BR>"
Response.Write "Error Description: " &
objConnection.Errors(0).Description & "<BR>"
Response.Write "Error Source: " & objConnection.Errors(0).Source &
"<BR>" Else
Response.Write "Generated Message Id: " &
objCommand.Parameters.Item("MsgId").Value & "<P>"
End IF

objCommand.Parameters.Refresh()


Do not use Parameters.Refresh in production code! It causes an extra
time-consuming trip to the database. Anyways, you seem to have the wrong
idea about what this does. Parameters.Refresh is used to create the
Parameters collection so the individual Parameter objects' values can be set
BEFORE the command is executed. After the Command is executed, the Return
parameter (and any output parameters) will contain the value returned by the
procedure. Using Refresh after execution will clear those values.
HTH,
Bob Barrows
Jul 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Chandra Mohan | last post by:
Hi All, I have a requirement of calling a Executable from SQL Server. I know we can use - EXEC @result = Master..xp_cmdshell @<command_string> However I want to get the return value (int)...
1
by: Seong-Kook Shin | last post by:
Hi. Just curiocity, Because of pre-ANSI C, it is possible to have a function without specifying return type of a function (which makes the return type 'int', though) and give no 'return'...
1
by: WLF | last post by:
I have the following function (C# behind aspx page): private void ButtonNewSupplier_Click(object sender, System.EventArgs e) { Response.Write("<script...
0
by: CoolCyber | last post by:
Hi, I wrote a simple webservice to insert data into db from the values sent to it. It works partially. very first time after system restart it works properly. after that it works partially....
1
by: csgraham74 | last post by:
Hi Guys, Im attempting to get an output value from my stored procedure. Im pulling my hair out at this one. any help appreciated. my code is as follows: Dim cnstring As String Dim iConn...
5
by: noLoveLusT | last post by:
hi everyone i am very very new to the sql server (2 days actually and ) so far i learned creating SPs etc but couldnt workout how to get return value from my prodecure my sp as follows...
4
by: Mick Walker | last post by:
Hi Everyone, I am stumped here. I have the following stored proceedure:P CREATE PROCEDURE . @SupplierSKU varchar(50), @RetVal int AS Select @Retval = count(*) from dbo.ImportLines Where =...
2
by: Mick Walker | last post by:
Public Sub CheckProduct(ByVal _ConnString As String, ByVal ProductList As List(Of Import_ImportLines.Lines)) Dim ReturnValue As Integer = 0 ' Our Return Value Dim conn As New SqlConnection Dim...
4
rrocket
by: rrocket | last post by:
I currently have this that sends a value to the DB and should return the information I need: Set RS = createobject("ADODB.Connection") Set x1 = server.CreateObject("ADODB.Command") With x1...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.