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!

Dbase index corrupt...help

Status
Not open for further replies.

ldojoles

Programmer
Apr 1, 2007
22
PH
gud day everyone !!! im using dbase for windows as my databse... since i have no UPS for my PC... i have no problem with my program but at times when there is power failure my indexfiles get corrupted... why ? whats the best thing to do?
 
Couple of things you could do...

Have you tried deleting the index (NDX?) file and then reindexing the table, perhaps using Database Desktop (Table, Restructure)? Once the index file is gone, you should be able to open the table.

If you mean how you could write an exception in the event the index is corrupted, you could do a DeleteFile for the index file, then run a query that will SQL CREATE or ALTER TABLE and add an INDEX.

You can also keep a blank DBF table (table B), along with it's index. When you index gets corrupted on table A, delete the table A index file. Add the records from table A to table B. Copy table B.DBF to A.DBF and copy B.NDX to A.NDX. Empty table B and get a standby generator. G'Luck.

Getting answers before I'm asked.
Providing answers if I can.
 
Unless your app is a single form with a DBGrid, there are usually areas of your program where the tables do not need to be open, like when the user is in a menu, for example. Most DB demo programs show opening the tables in OnCreate, the close the tables in OnDestroy, where in real life, this is a bad practice for the very reason you have described.

To protect your data, as a general rule, if a table doesn't need to be open in your code, close it.

I've gone as far as to put a timer on a DBGrid to close it if left open by a user. There nothing like a novice banging random keys to wake a suspended monitor with live data on the screen.

Roo
Delphi Rules!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top