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

Corrupt CDX

Status
Not open for further replies.

DaBuzz

Programmer
Nov 8, 2002
40
US
I have a remote connection that is less than stable. When the connection gets broken it corrupts the cdx of one table. Is there an easy way to recreate the index via an admin program. The area that I am encountering problems is the "Invalid Database" to fix the .dbc I can run Validate database - but not via a program. If I run Validate Database via the command window I can then create the index - but haven't figured out a way to validate the database and recreate the index all via a program.
 
I think you need to go with an ON ERROR DO MyErrorProgram.

MyErrorProgram would have a CASE or IF to catch the appropriate error number (from AERROR()) and then do a re-build routine.

I am not an expert error handler as I usually fly by the seat of my pants, but I've seen some good example here (maybe in the FAQ section)...

Brian

 
DaBuzz,

I agree with Brian about using an error-handler. These are the errors that you should trap:

15, 41, 19, 20, 23, 26, 112, 114, 1124, 1683

(Some of the above indicate a corrupted table rather than a corrupted index, but it does no harm to include them in your check.)

Once you have detected one of these errors, issue an INDEX command to recreate the index.

Mike

Mike Lewis
Edinburgh, Scotland

My Visual Foxpro web site: My Crystal Reports web site:
 
I agree on using an error-handling routine. The problem I am running into is the cdx is corrupt so I can not issue an index command. I have to delete the cdx and recreate it, but that leaves an "Validate Database" requirement which validate database can only be ran from a command window - not via a program.

I need a way to fix the database (validate) which will then allow me to recreate the index programmatically.
 
DaBuzz,

Sorry, but I don't understand the problem. If the index is corrupted, you don't have to delete the entire CDX. Just drop the index and then recreate it with the INDEX command. (I agree that REINDEX wouldn't work, but that's not what I'm suggesting.)

You shouldn't need to validate the database.

Or am I missing something?

Mike

Mike Lewis
Edinburgh, Scotland

My Visual Foxpro web site: My Crystal Reports web site:
 
Well my lack of knowledge must be shining through.

The message I get is "Index does not match table. Delete index file and re-create index."

I can't seem to drop the index unless it is open.
Via the command window I can delete the file, run validate database - which then lets me recreate the index. However, I can not run validate via a program.
My quick solution is a batch file that copies up a new blank table and cdx. However, if there is a way of preserving the data and getting back to where we were in data entry that would be great.

 
What you need is exclusive access. Most probably you just experienced it can be done via IDE/comamnd window, because SET EXCLUSIVE ON is the default setting of VFP, although I dislike that...

If you have a healthy database run gendbc.prg on it (you'll find it in the Home() dir under ./tools/gendbc), this generates all code needed to buidl the dbc with table structures and indexes, relations, stored procedures for referential integrity, connections, local and remote views. Then pick out the code you want. Another solution is to use a healthy backup of the cdx file (which doesn't need to be up to date, but includes correct index structure information in it's header) and reindex the table.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top