Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reindex CDX files

Status
Not open for further replies.

Rich196

Programmer
May 17, 2003
42
US
I have read everything I can get my hands on about recovering from CDX file corruption and I have written code that turns off the CDX present bit in the file header, deletes the CDX and uses FAQ1033 logic to re-build the index. I am using a DBC not free tables in VFP8. All works fine until I go to USE the table to recreate the CDX and then I get "Primary key property invalid, please validate database." Since you cannot validate when running a procedure (it wouldn't let me and I really don't want the end users to have to do that anyway) is there a way to get the table open to reindex it and create the new CDX? I do not have Stonefield Database Toolkit, yet!

Thanks,
Rich
 
Rich,
The sneaky way that I've used in the past is to simply have a good copy of a CDX file backed up (it can even be totally empty as long as it matches the table and the DBC), and then replace the bad CDX with this backup. Immediately USE the table Exclusively and REINDEX. While it's not as automatic or reliable if you don't keep an updated copy around, it does work. (Note: When
I say updated, I don't mean that the data has to match, just that the index information in the CDX header has got to match the .DBC information.)

Rick
 
Have you tried the code I posted in thread184-755689?

A corrupt CDX may well give you a problem though, I can see that. Another approach that is similar in nature to what Rick suggested is to remove that table from the database, create a new blank table with cdx and then pour the data from the old table to the new. Or maybe it would be enough for you to remove the table from the database and then add it back in given the problem you say you are getting from the dbc, it may be enough to keep you from having to do a VALIDATE DATABASE RECOVER which can bring up some pretty scarey messageboxes for the user. Just some thoughts, take them for what they are worth.

boyd.gif

craig1442@mchsi.com
"Whom computers would destroy, they must first drive mad." - Anon​
 
craigsboyd,

I would advise that you not do things that way. You'll lose all long field names.

IMO, doing a DELETE TAG ALL, then INDEX is the second best way of taking care of corrupt indeces.

The best way is to elimate the cause of the problem. Some issues are listed at
Craig Berntson
MCSD, Visual FoxPro MVP, Author, CrysDev: A Developer's Guide to Integrating Crystal Reports"
 
Have you considered making and using a DBF Control Table?

In there you would keep the Table name(s), Index TAG name(s), and Index Expression(s).

Then you would periodically DELETE TAG ALL and you would have the information necessary (by scanning through your Control Table) to INDEX anew for each and every TAG of each and every Table.

Good Luck,
JRB-Bldr
 
I should have mentioned that DELETE TAG ALL will also remove any persistant relations stored in the database. I *HIGHLY* recommend that you look at Stonefield Data Tools (
Craig Berntson
MCSD, Visual FoxPro MVP, Author, CrysDev: A Developer's Guide to Integrating Crystal Reports"
 
Thanks guys for all your help! The light bulb finally lit and I understand now why it is failing. Since I have persistent relations I need to keep intact I can't do the DELETE TAG ALL so for now will follow Rick's suggestion and keep a copy around so that in my ON ERROR routine I can copy them in and REINDEX.

Also, I know I need to get Stonefield but Mike Lewis said I would probably have to "engineer" it into my app which might be difficult. Does anyone know if it can be put in an existing app and if so how hard it really is?

Thanks again,
Rich
 
Rich,
I use SDT in a number of apps - I just updated my 10 developer subscription at the beginning of the week. It can be as simple as adding a couple menu items that point to some utility programs that are supplied. Of course if you want it to automatically check for updates to your database / tables / indexes / views / relationships /RI code / stored procedures OR automatically fix database/table/index header problems, that takes a bit more work, but it's quite doable. Stonefield support can help you too, through email and a forum on the UT (
Rick
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top