在大約2380行後,在運行此代碼的ASP頁上超過13000行的SQL Server Studio中需要1秒鐘的視圖超時。在經典ASP中將SQL導出到Excel的更快方式?
有沒有更好的方式來做到這一點?我一直在尋找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
頁面崩潰,並預計'和identifer'點,我已經更新了我的職務與示例代碼字'Class' – 2012-07-31 13:03:20
取自我發佈的鏈接。它在我的測試中非常快速地工作。 – BradBrening 2012-07-31 13:14:06
如果您嘗試了此代碼,並且它在「類」上崩潰,請確保您沒有嘗試將代碼複製/粘貼到函數或子代碼中。更好的是,只用Class代碼創建一個新的ASP文件,然後將該文件包含到您的頁面中,您將在其中進行大量字符串連接。 – BradBrening 2012-07-31 13:18:45