我需要编写一个小的VBScript来调用带有输入变量的SQL过程。我没有太多使用VBscript的经验,而且我得到了一个我无法找到解决方案的错误。我收到的错误是:
OnNewRecord(第14行):[ODBC Firebird驱动程序] [Firebird]动态SQL错误输入参数不匹配的过程TEST
我写的VBScript是:
Const Connection = "DRIVER=Firebird/InterBase(r) driver;UID=SYSDBA;PWD=masterkey;DBNAME=C:\Users\wouter\FOR-TESTING.fdb;"
Const adParamInput = 1
Const adInteger = 3
Set myConn = CreateObject("ADODB.Connection")
myConn.Open Connection
Set spCommand = CreateObject("ADODB.Command")
spCommand.Commandtext = "TEST"
spCommand.CommandType = 4
Set parameter = spCommand.CreateParameter(, adInteger, adParamInput, 4, 5)
Set spCommand.ActiveConnection = myConn
spCommand.Execute
myConn.Close
这个VBscript正在调用以下过程:
CREATE OR ALTER PROCEDURE TEST (ID INTEGER)
AS BEGIN
UPDATE MATERIAL_LABEL SET PRINTED = 'T', HANDLED_DATE = CURRENT_TIMESTAMP
WHERE ID = :ID;
END
ID INTEGER
应该是一个变量输入,但是用于使用数值5来测试代码。我认为它与需要不同类型输入的过程有关但我可以&#39 ;找到哪个。
答案 0 :(得分:0)
正如Ansgar Wiechers所说,你必须通过附加它将参数传递给存储过程:
spCommand.Parameters.Append parameter
答案 1 :(得分:-1)
我通过使用不同的方法插入我的数值来解决问题:
Const Connection = "DRIVER=Firebird/InterBase(r) driver;UID=SYSDBA;PWD=masterkey;DBNAME=C:\Users\wouter\FOR-TESTING.fdb;"
Set myConn = CreateObject("ADODB.Connection")
myConn.Open Connection
SQL = "execute procedure TEST 5"
Set dbconn = CreateObject("ADODB.Connection")
dbconn.Open connection
dbconn.Execute(SQL)
myConn.Close
- 更新 -
由于Ansgar Wiechers和Mihai Adrian给了我错误的原因,Geert bellekens警告我注意SQL注入的风险我尝试在我的VBScript中添加“追加线”,这也很完美!
特此我完成了VBScript:
Const Connection = "DRIVER=Firebird/InterBase(r) driver;UID=SYSDBA;PWD=masterkey;DBNAME=C:\Users\wouter\FOR-TESTING.fdb;"
Const adParamInput = 1
Const adInteger = 3
Set myConn = CreateObject("ADODB.Connection")
myConn.Open Connection
Set spCommand = CreateObject("ADODB.Command")
spCommand.Commandtext = "TEST"
spCommand.CommandType = 4
Set parameter = spCommand.CreateParameter(, adInteger, adParamInput, 4, 5)
spCommand.Parameters.Append parameter
Set spCommand.ActiveConnection = myConn
spCommand.Execute
myConn.Close
谢谢!