0

我的一个脚本中有一段代码出现语法错误。

if(status <> true and Request.QueryString("selectId") = "undefined") then
strConn ="PROVIDER=foobar;Server=foo;Database=foo;Uid=bar;Pwd=bar;"
Set cnt = Server.CreateObject("ADODB.Connection")
set rs1 = CreateObject("ADODB.Recordset") 
rs1.CursorLocation = adUseClient
cnt.ConnectionString= strConn
cnt.Open strConn

sql="Select * from rule1 where skucode='" & Request.Form("txthidden") & "' and letter1id  ='" & Request.Form("lrt1") & "' and letter2id ='" & Request.Form("Select1") & "' and letter3id ='" & Request.Form("Select2") & "'"
rs1.Open  sql,cnt,2,2
if not rs1.EOF then
Response.write("<script language=""javascript"">alert('Rules already exists!');</script>")
else

  sql="INSERT INTO rule1 (letter1id,letter2id,letter3id,HTML,skucode) VALUES "
  sql=sql & "('" & Request.Form("lrt1") & "',"
  sql=sql & "'" & Request.Form("Select1") & "',"
  sql=sql & "'" & Request.Form("Select2") & "',"
  sql=sql & "'" & Request.Form("txthtml") & "',"
  sql=sql & "'" & Request.Form("txthidden") & "')"  
cnt.Execute sql
 Response.write("<script language=""javascript"">alert('Rules Added successfully!');window.location='" & "viewrule1.asp?skucodes=" & Request.Form("txthidden") &   "';</script>")
end if
rs1.Close
cnt.close

我得到的错误信息是:

Microsoft OLE DB Provider for SQL Server error '80040e14'

Incorrect syntax near the keyword 'close'.

/path/file.asp, line 75
4

3 回答 3

0

您可以完全分离它,而不是关闭它:

set cnt = Nothing
于 2012-09-18T18:32:43.847 回答
0

假设这是引发错误的最后一行,我将其替换为:

If IsObject(cnt) Then
    On Error Resume Next
    If cnt.State = 1 Then ' 1 = adStateOpen '
        cnt.Close
    End If
    Set cnt = Nothing
    Err.Clear
    On Error Goto 0
End If

cnt当它到达脚本的那部分时可能已经关闭,这就是它抛出错误的原因。在关闭之前检查它的状态需要用On Error Resume Next逻辑包装,否则它会抛出另一个错误。

于 2012-09-19T06:17:44.343 回答
0

应该没有问题。我想的是你的数据是否太长。有时它会在您的行限制超出时发生。SQL Server 6.5 允许最大行大小为 1962 字节,SQL Server 7.0 允许最大行大小为 8060 字节。它只是一个假设

于 2012-09-19T05:31:35.367 回答