Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

VBScript Running A Stored Procedure - Cannot Return Output as Int

Posted on 2012-03-19
3
Medium Priority
?
561 Views
Last Modified: 2014-07-26
Hello;

I've created a stored procedure that is called upon by a VBScript.  The VBScript passes two varchar parameters to the sp - User Name and Computer Name.  My intent of the SP is to return an integer to be used later in the script.  When the script runs, it errors out with the following error:

 Microsoft VBScript runtime error: Invalid or unqualified reference

I'm specifying the return value in the script as an integer, so I'm not sure where this is going wrong. I've attached the SP in a text file and the script used to run the SP, so if anyone out there can take a look and provide me some assistance I would much appreciate it.  Thank you!

stpMostUsedPCByUserID.txt

GetPCInfo.vbs
0
Comment
Question by:danner29
3 Comments
 
LVL 75

Accepted Solution

by:
Anthony Perkins earned 1060 total points
ID: 37742272
You are combining OUTPUT and RETURN parameters.  Choose one or the other.

This is how you do it with a RETURN parameter:
Your Stored Procedure:
CREATE PROCEDURE dbo.stpMostUsedPCByUserID  
	@userid VARCHAR(50),
	@compName VARCHAR(50)

AS

DECLARE @rtnValue integer

SET NOCOUNT ON;

SELECT	@rtnValue = COUNT(*) 
FROM	LOGON_SESSIONS  
WHERE	userid = @UserID
	AND Computer = @CompName

RETURN @rtnValue

Open in new window



And here is your VBScript:
...
cmd.ActiveConnection = cn
cmd.CommandType = adCmdStoredProc
			
				
sSql = "stpMostUsedPCByUserID"
cmd.CommandText = sSql
						 
With cmd
	.Parameters.Append .CreateParameter("@RETURN", adInteger, adParamReturnValue)
	.Parameters.Append .CreateParameter("@UserID", adVarChar, adParamInput, 50, Left(Right(oSysInfo.UserName,Len(oSysInfo.UserName) -3 ),InStr(Right(oSysInfo.UserName,Len(oSysInfo.UserName) -3),",")- 1))
	.Parameters.Append .CreateParameter("@compName", adVarChar, adParamInput, 50, Left(Right(oSysInfo.ComputerName,Len(oSysInfo.ComputerName) -3 ), InStr(Right(oSysInfo.ComputerName,Len(oSysInfo.ComputerName) -3 ),",")- 1))
End With	

'On Error Resume Next
cmd.Execute
rtnVal = .Parameters.Value("@RETURN")
WScript.Echo rtnVal
'on Error GoTo 0
...

Open in new window

0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

886 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