ADODB.Parameters 错误 '800a0e7c' 参数对象定义不正确.提供的信息不一致或不完整 [英] ADODB.Parameters error '800a0e7c' Parameter object is improperly defined. Inconsistent or incomplete information was provided

查看:20
本文介绍了ADODB.Parameters 错误 '800a0e7c' 参数对象定义不正确.提供的信息不一致或不完整的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我主要是一名 PHP 开发人员,但我有一些旧的 ASP 是我们以前的开发人员之一制作的,它坏了,我不知道如何修复它.我们有一个程序将一些变量发送到侦听器页面,该侦听器页面将这些数据与注册码和 msSQL 数据库进行比较,然后让程序知道注册码是否有效.

I'm primarily an PHP developer, but I have some old ASP one of our previous developers made that broke and I can't figure out how to fix it. We have a program that sends some variables to a listener page that compares that data to registration codes an msSQL database and then lets the program know if the registration code is valid.

我在哪里遇到以下错误

.Parameters.Append .CreateParameter("@code", adVarChar, 1, 50, x)

是第 134 行:

ADODB.Parameters 错误'800a0e7c'

ADODB.Parameters error '800a0e7c'

参数对象定义不正确.提供的信息不一致或不完整.

Parameter object is improperly defined. Inconsistent or incomplete information was provided.

/checkregistrationpro.asp,第 134 行

/checkregistrationpro.asp, line 134

我已经在包含文件中指定了我没有包含在代码中的任何命名常量,因此与此无关.

I've already specified any named constants in an include file that I have not included in the code, so it isn't to do with that.

我的连接字符串(我已经验证这些设置是正确的):

My Connection String (I've already verified that these settings are right):

set conn = Server.CreateObject("ADODB.Connection")
set cmd = Server.CreateObject("ADODB.Command")
sConnString = "Provider=sqloledb; Data Source=MYDATASOURCE; Initial Catalog=MYCATALOG; User ID=MYUSERID; Password='MYPASSWORD';"
conn.Open sConnString

我的代码:

...

Function BlockInjectCode(StrVal)
    BlockInjectCode = Replace(StrVal,"--","")
    BlockInjectCode = Replace(BlockInjectCode,"'","")
    BlockInjectCode = Replace(BlockInjectCode,"""","")
    if instr(lcase(BlockInjectCode),"<") > 0 then
        BlockInjectCode = ""
    end if
End Function

    x = BlockInjectCode(Request.QueryString("rid"))
    uid = BlockInjectCode(Request.QueryString("uid"))
    chkcode = BlockInjectCode(Request.QueryString("Code"))
    CheckPro = BlockInjectCode(Request.QueryString("pro"))
    CheckProProd = BlockInjectCode(Request.QueryString("prod"))
    CheckProMac = BlockInjectCode(Request.QueryString("mac"))
    MacAdd = CheckProMac

    CodeValid = False

    if x <> "" and uid <> "" then

        '-- Get information about this registration code.   
        sqlStr = "select * from MYTABLE where Code = ? and IsValid = 1"

        set cmdCodes = Server.CreateObject("ADODB.Command")
        Set cmdCodes.ActiveConnection = Conn
        cmdCodes.CommandText = sqlStr
        with cmdCodes
            .Parameters.Append .CreateParameter("@code", adVarChar, 1, 50, x)
        end With    
        Set rsCodes = cmdCodes.execute      
...

推荐答案

常见的可能是你没有定义 adVarChar,所以 CreateParameter() 方法是 定义不正确".

Common occurrence is likely you do not have adVarChar defined, so the CreateParameter() method is "improperly defined".

这只是 ADODB 库中众多命名常量之一的示例.处理此问题的一种混乱方法是自己定义值;

This is just an example of one of the many named constants found in the ADODB Library. A messy approach to dealing with this is to just define the value yourself something like;

Const adVarChar = 200

这种方法的问题是您必须定义所有命名常量,这可能会让人头疼.另一种方法是跳过整个命名常量,只使用整数值,所以调用是;

The problem with this approach is you then have to define all the named constants which can be a headache. Another approach is to just skip the whole named constants thing and just use the integer values, so the call would be;

.Parameters.Append .CreateParameter("@code", 200, 1, 50, x)

然而,这并不容易阅读,尽管看起来您已经使用 1ParameterDirectionEnum 值(即命名常量 adParamInput)执行此操作 在 ADODB 库中.无论如何,我不会推荐这种方法.

However this isn't easy to read although it looks as though you are doing this already with the ParameterDirectionEnum value of 1 which is the named constant adParamInput in the ADODB Library. Regardless I wouldn't recommend this approach.

更好的方法是使用 #include 指令,以便它在调用页面中包含您可能想要的所有命名常量定义,这就是大多数人的做法.微软为此目的提供了一个预定义的文件,即 IIS(或者可能是 MDAC 库安装,我不确定我的头脑),称为 adovbs.incadovbs.asp,通过包含此文件,您的页面将可以访问其中的所有命名常量定义.

A slightly better approach is to use an #include directive so that it includes in the calling page all the named constant definitions you could want and this is how most do it. Microsoft provide a pre defined file for this very purpose with IIS (or possibly the MDAC library installation I'm not sure off the top of my head) known as adovbs.inc or adovbs.asp, by including this file your page would have access to all the named constant definitions within.

这一切的原因是 VBScript 不支持类型库,所以在 Client 场景中自己定义它们或从 adovbs.inc 文件中复制和粘贴是你唯一的选择.然而,在 Server 场景中,我们仍然拥有 IIS 的强大功能,它可以让我们做一些时髦的事情.

The reason for all this is VBScript doesn't support type libraries, so in a Client scenario defining them yourself or copying and pasting from the adovbs.inc file is your only option. However in a Server scenario we still have the power of IIS which lets us do some funky things.

如果类型库可以只添加一次并且您不必担心它,那不是很好吗?不需要定义烦人的常量?让我们面对现实,它们已经存在于类型库中,那么为什么我们不能从那里得到它们呢?事实证明,我们可以感谢 METADATA 指令.

Wouldn't it be nice if the Type Library could just be added once and you don't have to worry about it?, no annoying constants to have to define? Let's face it they already exist in the Type Library so why can't we get them from there? Well turns out we can thanks to the METADATA directive.

这是一个例子;

<!--
   METADATA    
   TYPE="TypeLib"    
   NAME="Microsoft ActiveX Data Objects 2.5 Library"    
   UUID="{00000205-0000-0010-8000-00AA006D2EA4}"    
   VERSION="2.5"
-->

这种方法的美妙之处在于您可以将其用于任何类型库(最好暴露给 COM),您可以在一个页面中定义,或将其添加到 global.asa 已在整个 Web 应用程序中定义.

The beauty of this approach is you can use for any Type Library (ideally exposed to COM) and you can define in one page, or add it into the global.asa to have defined across the entire Web Application.

通过这种方法,您可以安全地使用类似的代码;

With this approach you are then safe to use code like;

.Parameters.Append .CreateParameter("@code", adVarChar, adParamInput, 50, x)


有用的链接

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆