【问题标题】:Classic ASP debug not working when a file is included包含文件时,经典 ASP 调试不起作用
【发布时间】:2012-09-01 04:55:45
【问题描述】:

在我的包含文件夹中,我有文件 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


 %>

调试不工作。但是如果我删除了包含行,那么调试就会工作,我会收到错误

Microsoft VBScript runtime error: Variable is undefined: 'ExecuteNonQuery

我只是不明白。我是 ASP 经典的新手。谁能告诉我它发生的原因。

【问题讨论】:

    标签: asp-classic


    【解决方案1】:

    对于函数是 ASP 经典,您需要使用括号,例如,

    ExecuteNonQuery(queryVal)
    

    应该可以解决您的问题。

    【讨论】:

    • 我已经尝试过了,但它不起作用。调试没有被调用,我也没有得到错误。删除包含文件会出现问题,并且包含它没有任何作用。
    【解决方案2】:

    问题出在语法上,我很困惑。我使用了“If 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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-13
      • 1970-01-01
      相关资源
      最近更新 更多