Delphi - BOF或EOF为True,或者当前记录已被删除
当我尝试在 MS SQL Server 2005 中选择一个空表时,出现此错误:“BOF 或 EOF 为 True,或者当前记录已被删除”。我在 Delphi 5 中使用 TADOConnection 和 TADODataSet 来连接数据库并检索数据。
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;
有没有一种方法可以检查数据库表是否为空而不发生此类错误?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
此错误最初是在更新 MDAC_TYP(从内存中更新到 2.6)时发生的。根据旧的 Borland 公告
“这是 SQL Server 提供程序中的一个错误。设置
CursorLocation = clUseClient
以消除错误。”Borland,但该链接不起作用。Embarcadero 现在将其托管在此处:ftp://ftpd.embarcadero.com/pub/delphi/devsupport/updates/adoexpress/d5adoupdate2.exe(感谢 Jeroen 的官方链接!)
我建议下载并安装 Embarcadero 站点上列出的所有补丁(假设您可以找到它们)。
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.
在此处下载 Delphi 5 的 ADO 更新:ftp://ftpd. embarcadero.com/pub/delphi/devsupport/updates/adoexpress/d5adoupdate2.exe
确保您还安装了常规更新:
还有更多更新(Corba、原始 ADO 安装)和语言(法语、德语),但这些应该可以帮助您继续。
曾经还有一个 http://info.borland.com/devsupport/delphi /download_files/zlibupdate.zip,但它不在 ftpd 服务器上。
——杰罗恩
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
这是很久以前的事了,但我记得 Delphi 5 中的这个问题通过 Delphi 更新解决了。早期版本的 ADO 组件存在严重
问题我还发现您的代码使用的不是典型的运行时创建组件,并且没有使用某些容器(例如数据模块或表单)(通常不好)来进行组件的可视化工作。有时通过 adoConnection.execute 运行简单查询也很有用。如果不使用可视组件,ADO 的 Recordset 对象的处理与 Delphi 的 AdoDataset 非常相似。
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 queries via adoConnection.execute. If you do not use visual components, handling of ADO's Recordset object is much the same as Delphi's AdoDataset.
由于我花了一整天的时间,所以这里是我最终所做的总结。
Delphi 5 Pro 使用 ADO Express 安装
以及下载链接(再次感谢 Jeroen Wiert Pluimers):
Delphi 5 Pro 更新:
ftp://ftpd.embarcadero.com/pub/delphi/devsupport/updates/delphi5/D5ProUpdate.exe
ftp://ftpd.embarcadero.com/pub/ delphi/devsupport/updates/delphi5/german/d5proupdate.exe
ADOExpress 更新包 1 和 2:
ftp://ftpd.embarcadero.com/pub/delphi/devsupport/updates/adoexpress/D5ADOUpgrade.exe
ftp://ftpd.embarcadero.com/pub/delphi/ devsupport/updates/adoexpress/d5adoupdate2.exe
并供将来参考一些用于构建下载链接的屏幕截图(区分大小写):
Since I spent a whole day on this, here is a wrap up of what I did in the end.
Delphi 5 Pro Installation with ADO Express
And the download links (many thanks again Jeroen Wiert Pluimers):
Delphi 5 Pro updates:
ftp://ftpd.embarcadero.com/pub/delphi/devsupport/updates/delphi5/D5ProUpdate.exe
ftp://ftpd.embarcadero.com/pub/delphi/devsupport/updates/delphi5/german/d5proupdate.exe
ADOExpress Update Packs 1 and 2:
ftp://ftpd.embarcadero.com/pub/delphi/devsupport/updates/adoexpress/D5ADOUpgrade.exe
ftp://ftpd.embarcadero.com/pub/delphi/devsupport/updates/adoexpress/d5adoupdate2.exe
And for future reference some screenshots to build the download links (case sensitive):