asp-classic - ADODB.Recordset 错误 '800a0bb9' 参数类型错误、超出可接受范围或相互冲突

标签 asp-classic sql-injection parameterized-query

我有一个使用 ASP Classic 的旧网站,最近有人要求我删除 SQL 注入(inject)攻击威胁。我正在尝试使用参数化查询,但这有点超出我的想象。

这是我的代码:

<% whatSector = request.querystring("whatSector")%>

    <%  adoCon.Open cString
        dim rs_client
        if whatSector="" then
    strSQL="SELECT * FROM clients ORDER BY alphabet"
    else

    Set objCommand = Server.CreateObject("ADODB.COMMAND")

    strCmd1 = "SELECT * FROM clients Where industrySector=? ORDER BY alphabet"

    Set objCommand.ActiveConnection = adoCon
        objCommand.CommandText = strCmd1
        objCommand.CommandType = adCmdText

    Set param1 = objCommand.CreateParameter ("whatSector",adVarChar, adParamInput, 50)
    param1.value = whatSector
    objCommand.Parameters.Append(param1)
    Set rs_client = objCommand.Execute()

    end if 
    set rs_client = server.CreateObject("ADODB.Recordset")
    rs_client.open strSQL,adoCon

%>

这似乎对我在另一个页面上有用(除了由于某种原因我必须删除用于分页的 recordCount 东西),但我在此页面上收到以下错误:

ADODB.Recordset error '800a0bb9'

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

/clients/clientspotlight_list.asp, line 50

第 50 行 - 是上述代码片段末尾的 rs_client.open。

我用过

    <!-- METADATA TYPE="TypeLib" NAME="Microsoft ADO Type Library" UUID="{00000205-0000-0010-8000-00AA006D2EA4}" -->

对于 adovbs.inc。

最佳答案

您的参数名称似乎格式不正确。尝试将 strCmd1 的分配更改为:

strCmd1 = "SELECT * FROM clients Where industrySector=@whatSector ORDER BY alphabet"

然后将 param1 的分配更改为:

Set param1 = objCommand.CreateParameter ("@whatSector",adVarChar, adParamInput, 50)

关于asp-classic - ADODB.Recordset 错误 '800a0bb9' 参数类型错误、超出可接受范围或相互冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19936293/

相关文章:

php - 将 MySQL 查询转换为可能为空值的准备语句

php - 使用 SET 语义参数化插入...重复键更新失败

c# - 字符到数字的转换过程失败

mysql - 对存储在 MYSQL 数据库文本字段中的数字进行排序

sql - sql查询权限被拒绝

sql-server - SQL Server 需要不同的日期格式

javascript - 单击提交按钮时如何调用 asp 函数?

php - 是否需要从数据库中转义用户输入?

python - Python 中的 SQL 注入(inject)预防 - 使用参数化查询是否足够?

php - 优化 MySQL 查询所需的建议