web hosting and development forums
Web Design and Development Forums Archive


Index - ASP in depth

Why do I get 'BOF or EOF' errors?


Post reply

Why do I get 'BOF or EOF' errors?
When doing searches or other SQL queries, you may have encountered this error:

ADODB.Field error '80020009'

Either BOF or EOF is True, or the current record has been deleted; the
operation requested by the application requires a current record.

or

ADODB.Recordset error '800a0bcd'

Either BOF or EOF is True, or the current record has been deleted.
Requested operation requires a current record.

The most probable cause, of course, is that there is no record. For example, it would happen with the following code, if none of the records cotnained 'frank' in the fname column:

[code:1]<%
set conn = CreateObject("ADODB.Connection")
conn.open <connection string>
set rs = conn.execute(<sql>)
do while not rs.eof
' process
rs.movenext
loop
' ...
%>
[/code:1]
To prevent this error from "blowing up" your ASP page, you need to trap for the case where no records are there. The easiest way to do this is by adding the following lines:

[code:1]<%
set conn = CreateObject("ADODB.Connection")
conn.open <connection string>
set rs = conn.execute(<sql>)
if not rs.eof then
do while not rs.eof
' process
rs.movenext
loop
else
response.write "No matches."
end if
' ...
%>[/code:1]

If you are sure there are results, you might check that you at the most recent version of MDAC (which you can download from Microsoft Data Downloads). For more information, see KB #230101.

Another possible reason is that you are using a stored procedure that operates on a temp table, or does other row-affecting operation prior to your select statement. To get around this, issue the following at the beginning of your stored procedure:

SET NOCOUNT ON

This will prevent "(n) row(s) affected" messages from being interpreted by the provider as a resultset.

If you can't change the procedure, you can use trial and error to add the following statement in order to move to the correct and populated resultset:

[code:1]<%
set conn = CreateObject("ADODB.Connection")
conn.open <connection string>
set rs = conn.execute(<sql>)
set rs = rs.nextRecordSet()
' ...
%>[/code:1]
  • Mark wrote:
    Why do I get 'BOF or EOF' errors?

I think you should find something better to do with you time...




Dubai Forum | Paris Forum | Webmaster Forum | Vegan Forum | Brisbane Forum | 3D Forum | Jobs in Dubai | Jobs in London | London UK Classifieds
Archive script by RedHo.com