包含文件时,经典ASP调试不起作用

时间:2012-09-01 04:55:45

标签: asp-classic

在我的include文件夹中,我有文件SqlOperations.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


 %>

调试无效。但是,如果我删除include行,那么调试工作,我得到错误

Microsoft VBScript runtime error: Variable is undefined: 'ExecuteNonQuery

我只是不明白。我是ASP经典新手。任何人都能告诉我其发生的原因。

2 个答案:

答案 0 :(得分:0)

对于ASP经典的函数,你需要使用括号,E.G。,

ExecuteNonQuery(queryVal)

应该解决你的问题。

答案 1 :(得分:0)

问题是语法,我很困惑。我用“如果checkSql == False那么”,语法错了它应该只有一个“=”符号。好吧,我修改了一点,现在它的工作正常。这是用于连接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