Solved

ODBC MFC CRecordSet performance

Posted on 1999-01-21
3
1,158 Views
Last Modified: 2008-03-17
I am writing a family tree program in Visual C++ 4.0 using local ODBC links to Paradox 5.0 or Access 97 (the final choice is immaterial unless one turns out to be significantly better than the other).  I am using CRecordSet derived objects to provide the data needed to draw the tree on screen.  The idea is to navigate around the tree with the mouse, each double click redrawing a restricted portion of the tree focused on the person where the click occurred.  Unfortunately it takes about 17 seconds to redraw, the delay being caused by requerying the recordsets.  This makes the program somewhat unusable and I haven't yet even created all the recordsets that will eventually be required.  Can anyone suggest ways I might speed things up a bit?

Things I have already tried include the following:

* Closing recordsets in between use and opening them again when a requery would be needed.  This was suggested by a company called DevCentral on the grounds that a lot of open recordsets take up a large amount of RAM.  Unfortunately this approach takes even longer than when they are left open and requeried as necessary.

* Using a single global CDatabase object and passing this to the CRecordSet constructors instead of letting them create their own individual connections.  This has been my approach from the start and was also suggested by DevCentral.

* Using queries which reside in the database instead of submitting SQL from the C++ program.  I have been unable to get Access queries to accept parameters submitted via ODBC (they expect to present interactive users of Access with a dialog box) and have failed to access Paradox queries at all via ODBC.  Calling a query from Access which did not require parameters still took about the same length of time.

* Using less recordsets to obtain the same information.  I wrote a single recordset with a long cumbersome SQL statement to obtain all of the information required in one go but because there were so many more fields to return this still took as long as using lots of smaller recordsets.

* Only obtaining minimal information to draw the tree, querying for additional information as required (photos, text entries etc).  In fact the information so far being requested is minimal because I am still testing prototypes of this application.  If I used any less information there would be nothing to display at all.

* Not changing details of the recordset in between requeries, except for the parameter data member(s).  This was suggested in the Visual C++ help system and is what I am doing in any case.  The fact that the help system mentioned performance at all leaves me somewhat pessimistic.

Is ODBC always this slow or am I not using it right?  Any help or suggestions gratefully received.

Phil Hudson
0
Comment
Question by:Hudson
3 Comments
 
LVL 3

Expert Comment

by:P_S_Price
Comment Utility
If memory serves me right issuing ODBC SQL commands causes all data to be passed to the local SQL engine for that engine to do a sort. Try using Native SQL code or revising you Database so that it contains Views that present the data in the order that you want and access via those views
0
 
LVL 6

Accepted Solution

by:
jpk041897 earned 100 total points
Comment Utility
There are a few tricks you can use:

1.- MFC uses the Jet engiene to communicate to ODBC, which means that you are using 2 layes of abstraction to contact the DB. With Paradox you don´t have a choice but with Access you can avoid one layer by using the DAO calls instead of the ODBC calls (the changes in code are minimal). Using CDaoRecordSet instead of CRecordSet should give you about a 30% increase in performance. It will also allow you to compact the DB as needed (which you can't do with ODBC).

2.- The ODBC drivers for both Access and Paradox do not support stored procedure calls, which is why your attempts to call queries failed. On the other hand, Access VBA is OLE2 compliant, so you could make the calls in that fashion, though if memory is a concern, this could be counter productive.

3.- Another way you can increase performance is to set up a hashing scheme. If your Primary key is a string, your avarage test will require half the lenth of the key tests to determine if it passes or fails the SELECT clause.

If you add a field to your table that contains, say the ASCII sum of the characters that make up the key, you could querry on that (integer) value instead. That will make all tests 4 bytes long (which is generaly a lot shorter than half the string length). The resulting record set will return some false positives ( abc produces the same integer as cba) but these can be eliminated localy with calls to strcmp before you display them to the list.

Hope these ideas help.
0
 

Author Comment

by:Hudson
Comment Utility
You state that using DAO instead of ODBC will give about 30% increase in performance - hence my pessimistic comment on Friday about giving up and writing my own internal database.  In fact I have now implemented it with DAO and what was taking over a minute now works in much less than half a second.  I'm now learing about QueryDefs since they claim to make things even faster.  Thanks for that suggestion, and the others, you've really saved the day here!
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

APEX (Application Express) is used to develop a web application from Oracle. SQL Workshop is one of the tools that comes with Oracle APEX to query or modify the database objects or to make any changes to the structure.
This article explains all about SQL Server Piecemeal Restore with examples in step by step manner.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now