0

我继承了一些旧的 asp/vb 代码,它抛出了一个我找不到修复的错误。

服务器是 Windows Server 2008,运行 IIS7,SQL 服务器是 2008。

这是代码:

<% @ Language=VBScript %>
<!-- #include file="dsn.asp" -->
<!-- #include file="adovbs.inc" -->
<!-- #include file="libfunct.asp" -->

<%
'****************************************
'    VARIABLES DECLARATION
'****************************************
Dim sSql, RsInsCoInfo, PolicyID, InsCo, InsOffice
Dim qsPolicyType, qsAttach, qsCLNT_ID, qsClientID
Dim CostArray(10)
Dim DescriptionArray(10)
'****************************************
'    END VARIABLES DECLARATION
'****************************************


'********************************************
'    RETRIEVING THE QUERYSTRINGS
'********************************************
qsAttach     = Request.QueryString("Attach")
qsCLNT_ID    = Request.QueryString("CLNT_ID")
qsClientID   = Request.QueryString("ClientID")
qsPolicyType = Request.QueryString("PolicyType")
qsReQuote    = Request.QueryString("ReQuote")
qsPolicyID   = Request.QueryString("PolicyID")
'********************************************
'    END RETRIEVING THE QUERYSTRINGS
'********************************************


'**********************************************
' RETRIEVING THE INSURANCE COMPANY DETAILS
'**********************************************
'Get the insurance company details
Set RsInsCoInfo  = Server.CreateObject("ADODB.RecordSet")

sSQL = "SELECT InsuranceCo.*,FormPolicy.* FROM insuranceCo,FormPolicy"
sSQL = sSQL & " WHERE FormPolicy.INS_EF <= CONVERT(smalldatetime,'" & dbSaveDate(Date) & "',101)"
sSQL = sSQL & " And FormPolicy.INS_ET >= convert(smalldatetime,'" & dbSaveDate(Date) & "',101)"
sSQL = sSQL & " AND FormPolicy.PolicyType ='"  & qsPolicyType & "'"
sSQL = sSQL & " AND InsuranceCo.INS_ID = FormPolicy.INS_ID"

'response.write ssql
'response.end
RsInsCoInfo.Open sSQL, OLEDBConnStr, adOpenStatic, adLockReadOnly, adCmdText

If Not RsInsCoInfo.EOF then
    InsOffice = RsInsCoInfo("INS_Office")
    InsCo     = RsInsCoInfo("INS_DS")
Else
    Response.write "<b>No underwriter available.  Please contact the system administrator.<br>"
    Response.write sSQL
    Response.end
End if

'Close and free
RsInsCoInfo.close
Set RsInsCoInfo = Nothing
'**********************************************
' END RETRIEVING THE INSURANCE COMPANY DETAILS
'**********************************************



'*********************************************************************************
'              CLIENT SEQUENCE NUMBER INCREMENT FOR THIS POLICY TYPE
'*********************************************************************************
If Not qsReQuote Then
   newPolicyNumber = qsClientID & qsPolicyType
   Set RsSequence    = Server.CreateObject("ADODB.RecordSet")
   sSQL = "SELECT * FROM Policy WHERE PolicyNumber like '%" & newPolicyNumber & "%' AND Clnt_ID=" & qsCLNT_ID
   RsSequence.Open sSQL, OLEDBConnStr, adOpenStatic, adLockReadOnly, adCmdText
   If RsSequence.recordcount > 0 then
       PolicyID = 00
       While not RsSequence.eof
          If right(RsSequence("PolicyNumber"), 2) > PolicyID then
             PolicyID = Cstr(right(RsSequence("PolicyNumber"), 2))
                response.write PolicyID & "<br>"
          End if
          RsSequence.moveNext
       Wend
       PolicyID = PolicyID + 1
       If PolicyID < 10 then
          PolicyID = "0" & CStr(PolicyID)
       End If
   Else
      PolicyID = "01"
   End If
   RsSequence.close
   SET RsSequence = NOTHING
End If
'*********************************************************************************
'             END CLIENT SEQUENCE NUMBER INCREMENT FOR THIS POLICY TYPE
'*********************************************************************************


'*********************************************************************************
'             UPDATING ADDITIONNAL FIELD TO THE QUOTE CREATION
'*********************************************************************************
'Setting var
Dim strConnection, SQL_Upsate, newPolicyNumber
newPolicyNumber = qsClientID & qsPolicyType & PolicyID


If Not qsReQuote Then
   'Insert Sql Statement
   SQL_Update = "UPDATE Policy SET CLNT_ID=" & qsCLNT_ID & ","
   SQL_Update = SQL_Update & " InsuranceCo='"& InsCo & "',"
   SQL_Update = SQL_Update & " Office='"& InsOffice & "',"
   SQL_Update = SQL_Update & " StatusID="& 0 & ","
   SQL_Update = SQL_Update & " PolicyNumber='" & newPolicyNumber & "'"
   SQL_Update = SQL_Update & " WHERE PolicyID=" & qsAttach
Else
   'Insert Sql Statement
   SQL_Update = "UPDATE Policy SET CLNT_ID=" & qsCLNT_ID & ","
   SQL_Update = SQL_Update & " InsuranceCo='"& InsCo & "',"
   SQL_Update = SQL_Update & " Office='"& InsOffice & "',"
   SQL_Update = SQL_Update & " StatusID="& 0
   SQL_Update = SQL_Update & " WHERE PolicyID=" & qsPolicyID
End If


'Connection object and open the db
Set strConnection = Server.CreateObject("ADODB.Connection")
strConnection.Open OLEDBConnStr

' Executing the sql insert
strConnection.Execute SQL_Update

'Now Close the connection and free up
strConnection.Close
Set strConnection = Nothing

'*********************************************************************************
'               END ADDING ADDITIONAL FIELDS TO THE QUOTE CREATION
'*********************************************************************************


'*********************************************************************************
'                               DO CALCULATION
' - obtains file named Policy & 'Calculations.inc' = HHCalculations.inc etc.
'
' Modified by Stuart 20/5/03
'*********************************************************************************
set Rs = Server.CreateObject("ADODB.Recordset")

If Not qsReQuote Then
   sSQL = "SELECT Policy.* FROM Policy WHERE Policy.PolicyID=" & qsAttach
Else
   sSQL = "SELECT Policy.* FROM Policy WHERE Policy.PolicyID=" & qsPolicyID
End If

Rs.Open sSQL, OLEDBConnStr, adOpenkeyset, adLockPessimistic, adCmdText



'********************************************
'Response.write "<B>Policy table For Testing Only<P></b>"
'For Each fld in Rs.fields
'   Response.write fld.name & " = " & fld.value & "<br>"
'Next
'Response.end
'**********************************************

    Agent = 0
    Agent2 = 0
    AgentIntro = 0

'Open rsAccount for writing account entries to the PolicyAmount table
'** Comment derek to Stuart -> wont we be better here to find the agent with the code?

If Session("Agent") <> "" then
    set RsAgent = Server.CreateObject("ADODB.Recordset")
    sSQL = "Select * from Agents Where Name = '" & Session("Agent") & "'"
    RsAgent.Open sSQL, OLEDBConnStr, adOpenkeyset, adLockPessimistic, adCmdText
    Agent = rsAgent("commission")
End if


'If a park was involved for a new business then the introductory rate is required.
If Session("Village_Name") <> "" then
    set RsPark = Server.CreateObject("ADODB.Recordset")
    If IsNumeric(Session("Village_Name")) Then
       sSQL = "Select * from Park Where ParkID = '" & Session("Village_Name") & "'"
    Else
       sSQL = "Select * from Park Where ParkID = '" & Session("reParkID") & "'"
    End If
    RsPark.Open sSQL, OLEDBConnStr, adOpenkeyset, adLockPessimistic, adCmdText
    If RsPark.eof then
        Response.write "<b>" & ssql & "<P>No Park record found - Line 189 QuoteSave2.asp<P>Please contact you system administrator." 
        'Response.end
    Else
        AgentIntro = RsPark("Introduction")
    End if
End if

set RsAccount = Server.CreateObject("ADODB.Recordset")
set RsQuestions = Server.CreateObject("ADODB.Recordset")

If Not qsReQuote Then
   sSQL = "SELECT * FROM PolicyAmount WHERE PolicyID=" & qsAttach
Else
   sSQL = "SELECT * FROM PolicyAmount WHERE PolicyID=" & qsPolicyID
End If
RsAccount.Open sSQL, OLEDBConnStr, adOpenkeyset, adLockPessimistic, adCmdText

If Not qsReQuote Then
   sSQL = "SELECT * FROM PolicyQuestions WHERE PolicyID=" & qsAttach
Else
   sSQL = "SELECT * FROM PolicyQuestions WHERE PolicyID=" & qsPolicyID
End If

RsQuestions.Open sSQL, OLEDBConnStr, adOpenkeyset, adLockPessimistic, adCmdText

If Not qsRequote Then
   RsAccount.Addnew
End If
If Not qsRequote Then
   RsAccount("PolicyID") = qsAttach
   linkID = qsAttach
Else
   RsAccount("PolicyID") = qsPolicyID
   linkID = qsPolicyID
End If


sTargetFile = qsPolicyType & "Calculations.inc"
sTargetFileContents = GetFileContentsForExecution(sTargetFile)
Execute sTargetFileContents




'*********************************************************************************
'                            END DO CALCULATION
'*********************************************************************************





'*********************************************************************************
'                            WRITE COSTS TO THE TABLE
'*********************************************************************************

'Update data to the PolicyAmount table
RsAccount("PolicyAmount_IB") = Session("Login")

RsAccount("PolicyAmount_IT") = Date
RsAccount.Update

'**********************************************
'Response.write "<P><B>PolicyAmount table For Testing Only<P></b>"

'For Each fld in RsAccount.fields
'   Response.write fld.name & " = " & fld.value & "<br>"
'Next
'Response.write "<P><B><a href='default.asp'>Home</a>"
'Response.end
'***********************************************

'Clean up
RsAccount.Close
Set RsAccount = Nothing
Rs.update
Rs.Close
Set Rs = Nothing
RsQuestions.Close
Set RsQuestions = Nothing
'RsPark.close
'Set RsPark = Nothing

'Finish with this second saving so redirect to the policy page
If Not qsReQuote Then
   Response.redirect "Policy.asp?PolicyID=" & qsAttach & "&CLNT_ID=" & qsCLNT_ID & "&ClientID=" & qsClientID & "&PolicyType=" & qsPolicyType
Else
   Response.redirect "Policy.asp?PolicyID=" & qsPolicyID & "&CLNT_ID=" & qsCLNT_ID & "&ClientID=" & qsClientID & "&PolicyType=" & qsPolicyType
End If

%>

这是错误:“警告:文件 /quotesave2.asp 第 0 行多步 OLE DB 操作生成错误。检查每个 OLE DB 状态值(如果可用)。没有完成任何工作......”

它真的没有给我太多继续,任何帮助/见解将不胜感激。谢谢。

4

3 回答 3

0

这是经典的,我通过在执行之前将每个命令记录到数据库来处理这些问题。所以例如

log(sSql)
RsAccount.Open sSQL, OLEDBConnStr, adOpenkeyset, adLockPessimistic, adCmdText

其中 log(tekst) 是一个子文件,它将传递的文本写入 txt 文件。现在,当您遇到错误执行停止并检查您的日志。最后一个条目是生成错误的 sql。在交互式环境中执行此 sql,您可以轻松地调整文本并重试,并从 dbclient 获得更准确的错误。不知道 Sql Server 是什么,我使用 Oracle,它是 Sql*Plus,我确定 Sql Server 必须有其他人。更正 sql 后,将其粘贴到代码中,用变量替换文字。再次请求您的页面并执行上述操作,直到您的所有 sql 都正确为止。

于 2012-06-09T13:59:36.890 回答
0

首先,您的 SELECT 语句选择了多个具有相同名称的字段,这可能会导致问题。将您的声明更改为:(您可能需要更改 INS_DS 的表,我只是猜到了)

sSQL = "SELECT ic.INS_Office, fp.INS_DS "&_
    "FROM insuranceCo ic INNER JOIN FormPolicy fp ON ic.INS_ID = fp.INS_ID "&_
    "WHERE fp.INS_EF <= CONVERT(smalldatetime,'" & dbSaveDate(Date) & "',101) "&_
    "AND fp.INS_ET >= convert(smalldatetime,'" & dbSaveDate(Date) & "',101) "&_
    "AND fp.PolicyType = '"  & qsPolicyType & "'"

如果仍然是同样的错误,我记得在弄乱日期/时间字段时遇到了这个错误,所以这两个日期字段是可疑的。为了调试,尝试不使用该过滤器进行选择,看看会发生什么:

sSQL = "SELECT ic.INS_Office, fp.INS_DS "&_
    "FROM insuranceCo ic INNER JOIN FormPolicy fp ON ic.INS_ID = fp.INS_ID "&_
    "WHERE fp.PolicyType = '"  & qsPolicyType & "'"
于 2012-06-10T07:07:53.237 回答
0

在没有行号的情况下确定确切的问题真的很困难。我注意到在脚本的末尾,您正在向RsAccount记录集字段添加新记录并向其分配值。过去,由于 VBScript 变量和记录集字段类型之间的类型不匹配,我得到了“多步 OLE DB 操作生成错误”错误。仔细检查要更新的列的数据类型,如有必要,在将值分配给记录集之前显式转换值(例如,使用CLngfor numbers)。

于 2012-06-08T06:27:34.210 回答