ADODB.Field Error - Help!

Results 1 to 3 of 3

Thread: ADODB.Field Error - Help!

  1. #1
    illsorted Guest

    Default ADODB.Field Error - Help!

    I&#039m getting the following error from an ASP Page:<BR>===================================<BR>AD ODB.Field error &#039 800a0bcd&#039 <BR><BR>Either BOF or EOF is True, or the current record has been deleted; the operation requested by the application requires a current record. <BR><BR>/db/display.asp, line 365 <BR>===================================<BR><BR>I&# 039m retrieving records inside a loop. The first time through the loop it works fine, but after that it doesn&#039t. Here is the code:<BR>===================================<BR>fo r each item in printerlist<BR> set conn = server.createobject("adodb.connection")<BR> CONN_STR<BR> set rs2 = conn.execute("SELECT * FROM PRINTERTYPES WHERE PRINTERNAME = &#039" & item & "&#039")<BR><BR> servers = rs2("SERVERNAME") &#060;-- this is where the error occurs<BR> <BR> If IsNull(servers) or Len(servers) = 0 Then<BR> response.write "&#060;font face=""Arial"" size=""1"" color=""#FF0000""&#062;" & item & "&#060;/font&#062;&#060;hr width=""90%"" size=""1"" noshade&#062;"<BR> Else<BR> response.write "&#060;font face=""Arial"" size=""1""&#062;" & item & "&#060;/font&#062;&#060;hr width=""90%"" size=""1"" noshade&#062;"<BR> End If<BR> <BR> rs2.close<BR> set rs2 = nothing<BR> <BR> conn.close<BR> set conn = nothing <BR> <BR>next<BR><BR>

  2. #2
    Josh Rolfe Guest

    Default RE: ADODB.Field Error - Help!

    First of all, you should take your connection object outside of the loop - you only need to create that once, and it will slow your page down and use up more memory on your server to keep creating it. The problem is likely that your sql is not returning any records, so EOF is true for the recordset. You can&#039t reference an item in the recordset if the recordset is empty. Replace the line where the error occurs with ...If Not rs2.EOF Then servers=rs2("SERVERNAME") Else servers=""...

  3. #3
    Steve Cimino Guest

    Default Many problems

    You&#039re not checking to see if the record exists. You have a few problems with this code. First and foremost, do NOT keep setting and closing your connection inside ANY loops. It&#039s a waste of processor time, unless it&#039s necessary. Anything that doesn&#039t need to be set inside a loop, don&#039t set it. Secondly, don&#039t select * when you only want one field.<BR><BR>So:<BR>set conn = Server.CreateObject("adodb.connection")<BR>conn.op en CONN_STR<BR>sSQLString = "SELECT SERVERNAME FROM PRINTER...."<BR><BR>For each item in printerlist<BR>set rs2 = conn.execute sSQLString & "&#039" & item & "&#039"<BR> If Not rs2.EOF Then &#039Here&#039s what will clear up your error!<BR> &#039Do whatever<BR> Else<BR> Response.Write "No matching records found."<BR> End If<BR>set rs2 = Nothing &#039You&#039re doing this here because you&#039re going to use the rs over again.. an exception<BR>Next<BR>rs2.close<BR>Set rs2 = Nothing<BR>conn.close<BR>set conn = nothing<BR><BR>*REMEMBER----- Keep constants, unchanging values, object creation/destroying out of loops!!!<BR><BR>I think if you re-look at this situation, you may find a better and quicker solution than the one you&#039re using now, because this one seems quite inefficient (I&#039m only giving the solution to the question you posed). <BR><BR>Think about returning all possible printer types using one OR statement, and reading it through an array instead of doing a query each time. (Use WHERE PrinterName = &#039whatever&#039 OR PrinterName = &#039somethingelse&#039 OR ... Read through your printerlist, get all the item values, and THEN query).<BR><BR>Good Luck!<BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts