2012-09-18 100 views
0

我的一個腳本中有一段代碼出現語法錯誤。關鍵字'close'附近的語法不正確

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 
+0

'cnt.close()'後面有'End If'丟失。 –

+0

@ j.w.r這將導致編譯錯誤(語法錯誤),但實際的錯誤消息是運行時錯誤。 –

+0

線75是什麼?此外,請嘗試更改'rs1.Open sql,cnt,2,2'到'Set rs1 = cnt.Execute(sql)'它可能有所幫助。 –

回答

0

,而不是關閉它,你可以完全脫離它:

set cnt = Nothing 
0

不應該有問題。我的想法是,如果你的數據太長或沒有。有時會在行數超過時發生。 SQL Server 6.5允許最大行大小爲1962字節,而SQL Server 7.0允許最大行大小爲8060字節。它只是一個假設

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邏輯中,否則它會拋出另一個錯誤。

相關問題