I am creating a simple Delphi 7 app to compare some records in an Access table with those in a SQL Server 2008 table. The Access table has 2600 records and I loop through each of them looking for a record in the SQL table with the same value in 2 fields. For some reason it is running very slowly and when I put some timing code in I found that after the first 50 or so records, the time to excecute the query keeps increasing. Eventually it was taking more than 1.5 seconds for each instance. The code is below.
tblContacts is the Access table and Qry1 runs on the SQL Server. The query is cursor location clUseClient, cursor type ctOpenForwardOnly, lock type ltReadOnly. The Attorneys table is indexed on a combination of the 2 search fields (FirstName + LastName).
I found that if I used a Locate on the SQL Server table it was about 5 times faster. But why would the query be so slow and keep getting slower?
while not tblContacts.EOF do begin
Qry1.SQL.Add('SELECT * FROM Attorneys WHERE Firstname=' + QuotedStr(FirstName));
Qry1.SQL.Add('AND Lastname=' + QuotedStr(tblContactsLastName.AsString));
// Code to add matching names to a list will be here