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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help modifying dbf and cdx file 1

Status
Not open for further replies.

dbassett74

Programmer
Dec 21, 2002
5
US
I'm trying to modify a .dbf database file with FoxPro. I'm able to open the table up and make changes, however, FoxPro doesn't seem to be updating the corresponding .cdx (index) file. So the application that uses this .dbf bombs. If I delete the .cdx file, open the .dbf file in FoxPro, then close it, FoxPro seems to create a .cdx file but the application still bombs. I also noticed the index file size is much smaller than the original, even though I didn't remove any records. That seems to tell me the .cdx file that FoxPro is creating, is not of the same format as the original.

Any help or direction on how to get the index file updated while keeping it in it's original format would be appreciated..

Dan
 
If you have the version of FoxPro the .dbf was created with, open the table, DISP STAT to note the details of the indexes, close the file, delete the .CDX file, recreate it with the INDEX command providing the key fields/expressions and tag names from the original.

I'm assuming when you say "changes" you mean to the table structure (MODIFY STRUCTURE). If you've made changes to any key expressions used by the .CDX, you will have to re-create it.

If you don't have the version the table was created with, you may want to provide information here regarding which version the app was created in and what version you do have to make changes with.

Hope this helps.
 
Thanks for the info. I will try what you have recommended and post the results. By the way, I didn't make myself very clear. I did not make any changes to the structure, I just removed 1 record. This make the application bomb. Nothing related to the record because the application does not depend on the record, it seems to be the fact that a record was deleted but it is still being referenced in the cdx file. When I modify a record, that seems to be okay, it's only when I delete a record. My guess is that there is a record count inside the cdx file so because the cdx file is not getting updated by FoxPro, when the application opens the table and views the cdx file for record count, it bombs.
 
Okay, I followed your instructions, but first I would like to point out that I am completely new to FoxPro, so you'll have to have some patience with me.

I opened the table, and entered DISP STAT in the command window and hit Enter. I then got a bunch of text in the background. It was weird because I couldn't scroll up or down so I had to take screen shots of each page. I then deleted the corresponding cdx file and ran the DISP STAT again. The information was identical. So, what am I doing wrong??

I'm using FoxPro 6.0. Also, another interesting thing is that when I click on the Table | Properties, it does not show that there are any indexes on the table, but how come there is a cdx file? Is that not an index file??
 
The .CDX file is an index file. The text in the outptut you are describing includes descritions of the index keys and tag names that you'll need in order to rebuild the indexes to match what they are originally. This info appears in the first few lines displayed.

If you are not altering the table structure, but only deleting a single record, the index should not be getting corrupted. It may be that you don't have the index open when making the deletion. How are you making the deletion - if the record is only marked deleted (No PACK has been issued) and you have DELETED set OFF, then the index will include the deleted record.

Is the .CDX file the same name as the .DBF? If so, the index should open automatically when you USE the table. Otherwise you will need to SET INDEX TO the .CDX file name after USEing the table.

From the command window execute a USE on the table, then issue the PACK, and then REINDEX command. If this doesn't solve your problem, then something is corrupt in the index and it needs to be recreated.

Hope this helps.
 
You can also look at the following FAQ on the Microsoft: Visual FoxPro forum on this site. Ramani has written some utility code to rebuild .CDXs.

"ReBuild your CDX index files"
FAQ184-1033
 
Got it to work based on your help! It turned out to be exactly what you said. I was not opening the index file and not issueing the pack command. As soon as I opened the index file, deleted a record and then issued pack, the index was properly updated and the application worked.

I can't thank you enough!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top