Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
806 views
in Technique[技术] by (71.8m points)

vbscript - Passing Parameters to a Stored Procedure using ASP

I'm trying to pass some parameters to a SQL stored procedure in my classic ASP. I've seen several posts on this and not sure what I'm doing wrong as I don't seem to see my discrepancy.

set conn = CreateObject("ADODB.Connection") 
conn.open ("DSN=SERVER;UID=username;PWD=pwd;Database=MyDatabase")

 set cmd = Server.CreateObject("ADODB.Command")
 set cmd.ActiveConnection = conn
 cmd.CommandType = adCmdStoredProc
 cmd.CommandText = my_proc
 cmd.Parameters.Refresh
 cmd.Parameters(1) = "MyParam"

set rs = cmd.execute

I'm getting the error

Arguments are of the wrong type, are out of acceptable range, or are in conflict 
with one another.

on the line cmd.CommandType = adCmdStoredProc. I also tried to do it the following way with the same error

set conn = CreateObject("ADODB.Connection") 
conn.open ("DSN=SERVER;UID=username;PWD=pwd;Database=MyDatabase")

 set cmd = Server.CreateObject("ADODB.Command")
 set cmd.ActiveConnection = conn
 cmd.CommandType = adCmdStoredProc
 cmd.CommandText = my_proc
 cmd.Parameters.Refresh
 cmd.Parameters.Append cmd.CreateParameter("@MyParam, adVarWChar, adParamInput, 50, "test")

set rs = cmd.execute
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

@KekuSemau is correct but let me a suggest a more efficient and manageable approach then using the adovbs constants file.

METADATA allows you to define a reference to the DLLs constants even if your using Late Binding as is the case in a Classic ASP environment. It's probably worth mentioning that you can add METADATA references in individual pages but then again why would you?

To use it simply add the METADATA tag to your global.asa file (should be located in the root of your Web Application).

<!-- 
METADATA TYPE="typelib" FILE="C:Program FilesCommon FilesSystemADOmsado20.tlb"
-->

Depending on the system the ADO Type Library maybe different, adjust the FILE attribute accordingly.

I use this approach in all my applications mainly for referencing constants in the ADO and CDO Type Libraries.

ADO Type Library

<!--
METADATA 
TYPE="typelib" 
FILE="c:program filescommon filessystemadomsado15.dll"
-->

CDO Type Library

<!-- 
METADATA 
TYPE="typelib" 
UUID="CD000000-8B95-11D1-82DB-00C04FB1625D" 
NAME="CDO for Windows 2000 Library"
-->

These are examples of my own personal references, file locations maybe different whereas UUID attributes should be exactly the same.

IMPORTANT:

Remember to remove any references to adovbs constant include file (adovbs.inc or adovbs.asp commonly) when using METADATA approach in your global.asa or you will get a

Name redefined error

Also METADATA is only available in IIS 4.0 and above.


Useful Links


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...