传统的ASP为每个循环结束为时尚早
我有我的ASP脚本中的一个非常奇怪的问题。这是一个简单的脚本,从数据库中读取信息到一个记录,并通过记录,每次输出HTML作为一个表行。
I have a very odd problem with one of my ASP scripts. It is a simple script, reads information from a database into a recordset and loops through the recordset, each time outputting HTML as a table row.
我在那里定期它会接近其每一个循环的结束是一个问题,它只是停止不通过所有的记录得到。我知道那是因为停止我生成的HTML只是竟把下来作为记录S或T。该脚本没有崩溃,因为下面的每个循环结束我该表和所有的HTML仍然是present。
I'm having an issue where periodically it gets close to the end of its for each loop and it just stops without getting through all the recordsets. I know it is stopping because my resulting HTML only goes as far down as S or T in the recordset. The script is not crashing because underneath the for each loop I end the table and all that HTML is still present.
奇怪的是它破过一次刷新,那么下一次我刷新它的工作原理 - 在SQL数据库中的数据是静态的,ASP脚本没有改变。一个负载就可以工作,它可以打破下。
The odd thing is it is broken one refresh, then the next time I refresh it works - the data in the SQL Database is static and the ASP script is not changing. One load it can work, the next it can break.
我不知道是怎么回事,所以任何的建议是值得欢迎的!
I have no idea what is going on here so any advice is welcome!
有一件事情我倾向于做的是编写SQL的网页,所以我可以看到发生了什么事情。此外,它可能会有所帮助写记录为调试页面的计数。
One thing I tend to do is write the SQL to the page so I can see what's going on. Also, it might be helpful to write the count of the recordset to the page for debugging.
尝试使用这样的:
const C_NO_DATA = "NO_DATA"
const C_ERROR = "ERROR"
const C_COL_IDENTIFIER = 0
const C_COL_ERROR_ID = 1
const C_COL_ERROR_MESSAGE = 2
const C_COL_SQL = 3
const C_COL_CONNECTION = 4
function GetDataSet(sqlString, connString)
'Initialise...
dim returnVal, rsData
on error resume next
'Define and open the recordset object...
set rsData = Server.CreateObject("ADODB.RecordSet")
rsData.Open sqlString, connString, 0, 1, 1
'Initialise an empty value for the containing array...
redim returnVal(0,0)
returnVal(0,0) = C_NO_DATA
'Deal with any errors...
if not rsData.EOF and not rsData.BOF then
'Store the data...
returnVal = rsData.GetRows()
'Tidy up...
rsData.close
set rsData = nothing
select case err.number
case 3021 'No data returned
'Do nothing as the initial value will still exist (C_NO_DATA)
case 0 'No error
'Do nothing as data has been returned
case else
redim returnVal(4,0)
returnVal(C_COL_IDENTIFIER,0) = C_ERROR
returnVal(C_COL_ERROR_ID,0) = err.number
returnVal(C_COL_ERROR_MESSAGE,0) = err.description
returnVal(C_COL_SQL,0) = sqlString
returnVal(C_COL_CONNECTION,0) = connString
end select
end if
on error goto 0
'Return the array...
GetDataSet = returnVal
end function
这个程序将直接读取数据到一个数组,所以你可以悠闲地检查。
This routine will read the data directly into an array so you can examine it at leisure.
- 编辑 -
我想补充这一点,我提供的code这样的理由是作为一个函数来提取所有的数据在一个去,而不是通过一个打开的数据库连接环。
Just to add to this, the reason I've provided the code like this is as a function to extract all of the data in one go rather than loop through an open database connection.