使用经典迁移的问题 ASP

Issue with migration using classic ASP

将站点从一台服务器迁移到另一台服务器时出现问题,这是我遇到的错误:

Microsoft Cursor Engine error '80040e21'

Multiple-step operation generated errors. Check each status value.

/common/classes/Cart.asp, line 110

第 110 行是:

fld.Value = Request(fld.Name)

这是导致问题的代码:

public function InsertOrder
    set rs = Server.CreateObject("ADODB.Recordset")
    rs.ActiveConnection = OrdersConnectionString
    rs.Source = "SELECT *  FROM "& OrdersTable
    rs.CursorType = 3
    rs.CursorLocation = 3
    rs.LockType = 3
    rs.Open()
    rs.AddNew
    For Each fld in rs.Fields
    if Len(Request(fld.Name)) > 0 then
    fld.Value = Request(fld.Name)
    end if
    Next
    rs.Update
    rs.Requery
    rs.Sort=OrderKey &" desc "
    OrderID=rs(OrderKey)
end function

以前用的是SQL2008,新服务器用的是运行 SQL2016.

感谢您提供任何想法。

从导致这个错误的代码来看,这很可能是幕后类型转换的问题。不知何故,数据库驱动程序无法将数据正确转换为正确的类型,因此您必须自己完成。

一种非常灵活的方法是定义 key/value 对(VBScript 字典可以适合这种情况),其中键是字段名,值是要将其转换为的类型价值。 (字符串、整数、双精度、日期)

示例代码如下:(未经测试,但只要您提供正确的详细信息,应该可以按原样工作)

Const FIELD_TYPE_STRING = 1
Const FIELD_TYPE_INTEGER = 2
Const FIELD_TYPE_DOUBLE = 3
Const FIELD_TYPE_DATE = 4
Const FIELD_TYPE_CURRENCY = 5
Function ConverFieldValue(rawValue, fieldType)
    ConverFieldValue = VBNull
    Select Case fieldType
        Case FIELD_TYPE_STRING:
            ConverFieldValue = CStr(rawValue)
        Case FIELD_TYPE_INTEGER:
            If rawValue<>"" Then ConverFieldValue = CLng(rawValue)
        Case FIELD_TYPE_DOUBLE
            If rawValue<>"" Then ConverFieldValue = CDbl(rawValue):
        Case FIELD_TYPE_DATE:
            If rawValue<>"" Then ConverFieldValue = CDate(rawValue)
        Case FIELD_TYPE_CURRENCY:
            If rawValue<>"" Then ConverFieldValue = CCur(rawValue)
    End Select
End Function
Dim typeMapping
Set typeMapping = Server.CreateObject("Scripting.Dictionary")

'''***Add actual field names and types below:****
typeMapping.Add "Field1", FIELD_TYPE_STRING
typeMapping.Add "Field2", FIELD_TYPE_INTEGER
typeMapping.Add "Field3", FIELD_TYPE_DOUBLE
typeMapping.Add "Field4", FIELD_TYPE_CURRENCY
typeMapping.Add "Field5", FIELD_TYPE_DATE
'''*************************************************

Dim currentFieldType, currentFieldValue
Set rs = Server.CreateObject("ADODB.Recordset")
rs.ActiveConnection = OrdersConnectionString
rs.Source = "SELECT *  FROM "& OrdersTable
rs.CursorType = 3
rs.CursorLocation = 3
rs.LockType = 3
rs.Open()
rs.AddNew
For Each fld in rs.Fields
    if Len(Request(fld.Name)) > 0 then
        currentFieldType = typeMapping(fld.Name)
        currentFieldValue = ConverFieldValue(Request(fld.Name), currentFieldType)
        fld.Value = currentFieldValue
    end if
Next
rs.Update
rs.Requery
rs.Sort=OrderKey &" desc "
OrderID=rs(OrderKey)