ADODB.COMMAND usually noticed a parameter

xiaoxiao2021-03-06  79

When we call the SQL Server stored procedure in the ASP, we usually use the following code if you use the AdoDb.command object:

DIM CMD, RS

SET cmd = server.createObject ("adodb.command")

cmd.activeConnection = conn

cmd.commandtype = adcmdstoredProc

cmd.commandtext = "Testproc"

cmd.parameters.Append Cmd.createParameter ("@ a", Adinteger, Adpaaminput, 4, 1)

Cmd.Parameters.Append Cmd.createParameter ("@ b", Advarchar, Adparaminput, 50, 'b')

...

SET RS = cmd.execute

Today I found that when I was debugging a program, I prompting a parameter without assigning a value, but I didn't assign a value. So I opened the SQL Server's event detector, executed a program, capturing the SQL statement actually ASP sent to SQL Server is actually as follows:

Execute Testproc 1, 'B', ....

The reason is now clear that the ADO engine does not translate the call to the stored procedure into a complete syntax, but uses the above-mentioned shorthand, so that when a certain parameter is lost, it is possible to misunderstand another because of misalignment. A parameter is lost.

Then I checked the properties of the Command object and added as follows:

cmd.namedparameters = TRUE

That is to say, specify the form of variables to be explicitly named, then execute the program, discover the statements captured in the event detector becomes:

EXEC TESTPROC @a = 1, @B = 'b', ...

The parameters of the error are also correct.

Everything is ok now

转载请注明原文地址:https://www.9cbs.com/read-94497.html

New Post(0)