Delphi ADO 与 MS Access - 运行特定查询后查询时间减少
我有一个带有 3 个窗体的 Delphi 应用程序,我使用 Access 2003 和 Microsoft.Jet.OLEDB.4.0,我在主窗体中有一个 ADOconnection 并在所有窗体中使用它。
我使用 2 个 .mdb 文件,其中 my.mdb 具有指向 org.mdb 表的链接。
一切正常,但速度非常慢。因此,经过长时间的搜索,我得出了这一点。
我不知道为什么,但在运行此查询后,所有其他查询的速度都显着提高(从 10 秒缩短到 1 秒)。 (甚至不包括链接表的查询)。
表 tb_odsotnost 位于 my.mdb
表 Userinfo 已链接。
with rQueries.ADOQuery1 do
begin
Close;
SQL.Clear;
SQL.Add('SELECT DISTINCT tb_odsotnost.UserID, Userinfo.Name FROM tb_odsotnost');
SQL.Add('LEFT JOIN Userinfo ON Userinfo.UserID = tb_odsotnost.UserID');
SQL.Add('WHERE datum BETWEEN '+startDate+' AND'+endDate);
SQL.Add('ORDER BY Userinfo.Name ASC');
Open;
end;
我尝试在另一台装有 win7 和 MS Access 2007 的计算机上运行我的应用程序,结果是相同的。
好的,现在我只是在 FormActivate 上运行此查询,但这不是永久解决方案。
I have a Delphi application with 3 forms, I'm using Access 2003 and Microsoft.Jet.OLEDB.4.0, I had an ADOconnection in the main form and use it in all forms.
I use 2 .mdb files, where my.mdb has links to org.mdb tables.
Everything works, but very slowly. So after long hours of searching I came to this.
I don't know why, but after I run this query all other queries increase in speed dramatically (From 10 seconds under 1 second). (Even queries that don't unclude linked tables).
Table tb_odsotnost is in my.mdb
Table Userinfo is linked.
with rQueries.ADOQuery1 do
begin
Close;
SQL.Clear;
SQL.Add('SELECT DISTINCT tb_odsotnost.UserID, Userinfo.Name FROM tb_odsotnost');
SQL.Add('LEFT JOIN Userinfo ON Userinfo.UserID = tb_odsotnost.UserID');
SQL.Add('WHERE datum BETWEEN '+startDate+' AND'+endDate);
SQL.Add('ORDER BY Userinfo.Name ASC');
Open;
end;
I tried to run my app on another computer with win7 and MS Access 2007 and the result was the same.
Ok, for now I just run this query onFormActivate but this is not a permanent solution.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您对链接表运行查询时,Access(或 Jet 或 ADO)会获取数据库上的 ldb 文件锁。如果关闭查询,则下次查询链接表时必须重新获取该锁。解决此问题的推荐方法是始终保持后台数据集打开,以便不必每次都获取锁(强制锁保持有效)。
请参阅 http:// office.microsoft.com/en-us/access-help/improve-performance-of-an-access-database-HP005187453.aspx 并查看“提高链接的性能”表”部分。
如果这没有帮助,请查看 Access 中的表定义,看看是否为一对多关系中的表字段定义了子数据表。
When you run a query against a linked table, Access (or Jet or ADO) acquires a lock on the database for the ldb file. If you close the query, that lock has to be reacquired the next time you query the linked table. The recommended method to get around this is to always keep a background dataset open so that the lock doesn't have to be obtained each time (forcing the lock to remain in effect).
See http://office.microsoft.com/en-us/access-help/improve-performance-of-an-access-database-HP005187453.aspx and look at the "Improve performance of linked tables" section.
If that doesn't help, look at your table definitions in Access to see if you have subdatasheets defined for your table fields in one-to-many relationships.