2012-09-01 71 views
0

在我的包含文件夾我的文件SqlOperations.asp經典ASP調試時,包含的文件無法正常工作

<% 
    Option Explicit 

    Function CheckSqlConnection() 
     Dim sqlConnection, connString 
     connString = "Provider=SQLOLEDB.1;Persist Security Info=False; uid=sa; pwd=123456789;Initial Catalog=UserDatabase;Data Source=lakpa-pc" 
     Err.Clear 
     On Error Resume Next 
     SET sqlConnection = Server.CreateObject("ADODB.Connection") 
     sqlConnection.Open connString 

     If Err.Number <> 0 Then 
      CheckSqlConnection = false 
     End If 

     CheckSqlConnection = sqlConnection 
     On Error Goto 0 
    End Function 

    Function ExecuteNonQuery(sqlQuery) 
     Dim checkSql, sqlCmd 
     checkSql = CheckSqlConnection 
     If checkSql == False Then 
      Response.Write("Please check your connection string <br/>" & vbCrlf) 
      Response.End 
      ExecutenonQuery = False 
      Exit Function 
     End If 
     checkSql.Execute(sqlQuery) 
     ExecuteNonQuery = True 
    End Function 

%> 

然後當我把它從UserInformation.asp這是在根文件夾

<!--#include file="include/SqlOperations.asp" --> 
<% 
    OPTION EXPLICIT 

    dim fName, mName, lName,age,address,postCode,telephone, queryVal 
    fName = Request.Form("fName") 
    mName = Request.Form("mName") 
    lName = Request.Form("lName") 
    age = Request.Form("age") 
    address= Request.Form("address") 
    postCode = Request.Form("postCode") 
    telephone = Request.Form("telephone") 
    if fName <>"" then 
     queryVal = "INSERT INTO UserInfo(FirstName, MiddleName, LastName, age, Address, PostCode, Telephone) VALUES('" + fName +"','" + mName+"','" + lName+"','" + age +"','" + address +"','" + postCode +"','" + telephone +"')" 
     ExecuteNonQuery queryVal 

    end if 


%> 

調試不起作用。但是,如果我刪除包括行然後調試工程,我得到的錯誤

Microsoft VBScript runtime error: Variable is undefined: 'ExecuteNonQuery 

我只是不明白它。我是ASP經典新手。任何人都可以告訴我爲什麼會發生這種情況。

回答

0

那麼問題是語法,我很困惑。我用「如果checkSql == False Then」,語法錯了,它應該只有一個「=」符號。那麼我修改了一點,現在它的工作正常。這是用於連接ASP Classic與MSSQL。可能對別人有幫助。 感謝凱恩的回覆:)

Function CheckSqlConnection() 
    Dim sqlConnection, connString 
    connString = "Provider=SQLOLEDB.1;Persist Security Info=False; uid=sa; pwd=123456789;Initial Catalog=UserDatabase;Data Source=lakpa-pc" 
    Err.Clear 
    On Error Resume Next 
    SET sqlConnection = Server.CreateObject("ADODB.Connection") 
    sqlConnection.Open connString 

    If Err.Number <> 0 Then 
     CheckSqlConnection = false 
    End If 

    set CheckSqlConnection = sqlConnection 
    On Error Goto 0 
End Function 

Function ExecuteNonQuery(sqlQuery) 
    Dim checkSql 
    set checkSql = CheckSqlConnection 
    If checkSql = False Then 
     Response.Write("Please check your connection string <br/>" & vbCrlf) 
     Response.End 
     ExecutenonQuery = False 
     Exit Function 
    End If 
    checkSql.Execute(sqlQuery) 
    ExecuteNonQuery = True 
End Function 

Sub SqlConnectionClose(SqlConn) 
    SqlConn.Close() 
End Sub 
0

對於功能是ASP經典,你需要使用括號,例如

ExecuteNonQuery(queryVal) 

應該解決您的問題。

+0

我已經試過,但它不工作。調試沒有被調用,也沒有得到錯誤。 刪除包含文件給出了問題,並且包含它沒有任何作用。 –

相關問題