views:

108

answers:

3

This error showed when I tried to select on an empty table in MS SQL Server 2005: "either BOF or EOF is True, or the current record has been deleted". I have used TADOConnection and TADODataSet in Delphi 5 to connect and retrieve data from the database.

  Conn := TADOConnection.Create(nil);
  DataSet := TADODataSet.Create(nil);

  Conn.ConnectionString := 'Provider=SQLOLEDB.1;Password=sa;' +
                           'Persist Security Info=True;' +
                           'User ID=user;Initial Catalog=mydb;' +
                           'Data Source=MYPC\SQLEXPRESS;' +
                           'Use Procedure for Prepare=1;' +
                           'Auto Translate=True;Packet Size=4096;' +
                           'Workstation ID=MYPC;' +
                           'Use Encryption for Data=False;' +
                           'Tag with column collation when possible=False';
  Conn.LoginPrompt := False;
  Conn.Open;

  DataSet.Connection := Conn;
  DataSet.CommandText := 'SELECT * FROM MYTABLE';
  DataSet.Open;

  DataSet.Free;
  Conn.Free;

Is there a way to check if a database table is empty without incurring such error?

+2  A: 

It was long time agom but I recall that this problem in Delphi 5 resolves by Delphi update. Early version has serious problems with ADO components

P.S. Also I see that your code uses not typical runtime creation of components and does not use some container like data module or form (not good usually) for visual work with components. Also sometimes useful run simple quieries via adoConnection.execute. If you do not use visual components, handling of ADO's Recordset object is much the same as Delphi's AdoDataset.

If you don't use ADO's Recordset object for non-visual code, use `AdoDataSet.DisableControls` to vastly improve performance.
Gerry
+5  A: 

This error originally occured with an update to MDAC_TYP (to 2.6 from memory). According to an old Borland advisory "This is a bug in the SQL Server provider. Set CursorLocation = clUseClient to eliminate the error."

There was a ADOExpress patch available from Borland, but the link doesn't work. Embarcadero now host it here: ftp://ftpd.embarcadero.com/pub/delphi/devsupport/updates/adoexpress/d5adoupdate2.exe(Thanks for the official link Jeroen!)

I would recommend downloading and installing all patches listed on the Embarcadero site, assuming you can find them.

Gerry
I just figured out that those updates are dead
rajeem_cariazo
Edited to add links to official version on Embarcadero's ftp site
Gerry
+3  A: 

Download the ADO update for Delphi 5 here: ftp://ftpd.embarcadero.com/pub/delphi/devsupport/updates/adoexpress/d5adoupdate2.exe

Make sure you also have the regular update installed:

There are more updates (Corba, original ADO install) and languages (French, German), but these should get you going.

There also used to be a http://info.borland.com/devsupport/delphi/download_files/zlibupdate.zip, but it is not on the ftpd servers.

--jeroen

Jeroen Pluimers
Thanks, I wonder how you got these links, my Google skills isn't good
rajeem_cariazo
I got it, ftpc.borland.com is now replaced by ftpd.embarcadero.com but all the files and folders are the same
rajeem_cariazo
actually, they merged ftpc and ftpd into a new big ftp://ftpd, and a http://altd
Jeroen Pluimers