我有一个使用 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/