0

在 SQL Server Studio 中花费 1 秒时间查看超过 13000 行的视图在运行此代码的 ASP 页上在大约 2380 行之后超时。

有一个更好的方法吗?我一直在寻找 6 个月没有运气。

Server.ScriptTimeout=200
    dim updateNBK
    updateNBK = UCase(request.QueryString("SelTABLE"))

    dim allstring
    allstring = UCase(Request.QueryString("SelTABLE")) & " " & UCase(Request.QueryString("SelNBK"))


    allstring = LCase(allstring)
    dim checkforinject
    If(InStr(allstring, "'")<>0)then
        checkforinject = true
    Elseif(InStr(allstring, "--")<>0)then
        checkforinject = true
    End If

    If (checkforinject = true) then
        Response.Write("<b>Injection Detected</b><br/> You may not enter the following characters: ' or --")
    Elseif (checkforinject = false) then

    dim strSQL


        if(Request.QueryString("submitbutton") = "Download") then

        strSQL = "select COLUMN_NAME from INFORMATION_SCHEMA.COLUMNS  where TABLE_NAME = '" & UCase(request.QueryString("SelTABLE")) & "'"


        On Error Resume Next
        set arn = cnt.execute(strSQL)   

        dim datastr
        dim datahead
        datahead = "<table class='bluetable'><thead><tr><td colspan='30'>" & UCase(request.QueryString("SelTABLE")) & " contents</td></tr></thead>"
        dim columns
        colums = 0
        datastr = datastr & "<tbody class='datasheet'><tr class='selectblue'>"
        if not arn.EOF then
                    arn.movefirst

                    do
                        On Error Resume Next
                        datastr = datastr & "<td>" & arn(0) & "</td>"
                        columns = columns + 1
                        arn.movenext
                    loop until arn.EOF
                end if
        datastr = datastr & "</tr>"

        strSQL = "Select * from " & UCase(request.QueryString("SelTABLE"))

        if(UCase(Request.QueryString("SelNBK")) <> "") then

        strSQL = strSQL & " where SubmitterNBK = '" & UCase(Request.QueryString("SelNBK")) & "'"

        end if

        set arn = cnt.execute("Select TimestampColumnName from FormsInfo where FormOutput='" & UCase(request.QueryString("SelTABLE")) & "'")

        strSQL = strSQL & " ORDER BY " & arn(0) & " desc;"

        Response.Write "Test1"

        On Error Resume Next
        set arn = cnt.execute(strSQL)   
        dim counter
        counter = 0
        if not arn.EOF then
                    arn.movefirst
                    Response.Write "Test2"
                    dim cellnum
                    do
                    datastr = datastr & "<tr>"
                        On Error Resume Next
                        cellnum = 0
                        'datastr = datastr & "<td>" & arn.value.toString() & "</td>"
                        do
                        datastr = datastr & "<td>" & arn(cellnum) & "</td>"
                        cellnum = cellnum + 1
                        loop while cellnum < columns
                        arn.movenext
                        'Response.Write "TestLoop"
                        Response.Write "<br/>Loop ran " & counter & " times." 
                        counter = counter + 1
                    datastr = datastr & "</tr>"
                    loop until arn.EOF
                    Response.Write "<br/>Loop ended." 
        end if


        datahead = "<table class='bluetable'>"

        Response.Clear  

        Response.ContentType = "application/vnd.ms-excel" ' arbitrary 

        Response.AddHeader "Content-Disposition","attachment; filename=" & UCase(request.QueryString("SelTABLE")) & ".xls"

        Set adoStream = CreateObject("ADODB.Connection") 
        adoStream.Open() 
        adoStream.Type = 2

        Response.Write datahead & datastr 
        Response.Flush

        adoStream.Close 
        Set adoStream = Nothing 
        Response.End
4

2 回答 2

2

我怀疑您的问题在于 VBScript 在字符串连接方面很糟糕- 看起来您正在做很多事情。

尽管 .NET StringBuilder 类对 VBScript 不可用,但有几个有用的库/代码示例可用。一个例子在这里:http ://www.eggheadcafe.com/articles/20011227.asp

可能需要对您的代码进行一些修改,但我敢打赌性能会大大提高。

这是使用上面链接中的代码的示例。请注意,您可能希望将 FastString 类放在包含文件中,以便可以在其他地方重用它。

Dim test : Set test = new FastString
Dim I
For I = 0 To 1000
  test.Append("TESTING")
Next
Response.Write test.Concat

来自上面链接的代码:

Class FastString
  Dim stringArray, growthRate, numItems
  Private Sub Class_Initialize()
    growthRate = 50: numItems = 0
    ReDim stringArray(growthRate)
  End Sub
  Public Sub Append(ByVal strValue)
    ' next line prevents type mismatch error if strValue is null. Performance hit is negligible.
    strValue=strValue & ""
    If numItems > UBound(stringArray) Then ReDim Preserve stringArray(UBound(stringArray) + growthRate)
    stringArray(numItems) = strValue: numItems = numItems + 1
  End Sub
  Public Sub Reset
    Erase stringArray
    Class_Initialize
  End Sub
  Public Function Concat()
    Redim Preserve stringArray(numItems)
    concat = Join(stringArray, "")
  End Function
End Class

替代解决方案:

如果您不介意没有样式单元格,您可以利用 ADO 记录集的“GetRows”功能。这个很少使用的解决方案在这种情况下非常有用:

Dim tableRows : tableRows = arn.GetString(,,"</td><td>","</td></tr><tr><td>","&nbsp;")
Response.Write "<table class='bluetable'>" & tableRows & "</table>"

因此,您的输出变为:

Set arn = cnt.Execute(strSQL)   
Response.Clear  
Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader "Content-Disposition","attachment; filename=" & UCase(request.QueryString("SelTABLE")) & ".xls"
Dim tableRows : tableRows = arn.GetString(,,"</td><td>","</td></tr><tr><td>","&nbsp;")
Response.Write "<table class='bluetable'>" & tableRows & "</table>"
于 2012-07-30T21:18:30.183 回答
0

我怀疑构建它的字符串是什么让它变得如此缓慢。VBScript 在这方面很糟糕。

我曾经使用一个名为 clsString 的类来完成这种工作。

我想就是这样: http: //pcdispatchwiki.com/Intranet/includes/funcsSubsClasses.asp

从记忆里:

dim tmpStr : set tmpStr = new clsString
tmpStr.add "Hello"
tmpStr.add vbCRLF
tmpStr.add "World"
dim finalText : finalText = tmpStr.Value
于 2012-07-31T11:28:29.973 回答