“Key Violation” errors occur whenever a new record is created with a primary key that already exists. This means that the field you defined as your primary key must be unique on the table. No other record can have that value, and it generates a “Key Violation” error when this happens.
If you are not using Auto Increment fields just make sure the primary key does not exist and you are good to go.
This error is common on tables that use Auto Increment fields on the primary key.
To fix this, the AutoInc record that is hard-coded in the paradox table needs to be altered.
I developed a simple application that analyses every table in a given directory, checks the AutoInc field and automatically repairs them.
If you like my free work, please consider making a donation and help me pay for the hosting and all the coffee and beer I drink developing this free software.
Paradox AutoInc Repair
And here is the delphi code if you want to do this using your delphi programs.
This function will allow you to set your AutoInc field to the specified value :
function SetAutoInc(FileName: TFileName; NewValue:Longint): Boolean; begin with TFileStream.Create(FileName, fmOpenReadWrite) do try Result := (Seek($49, soFromBeginning) = $49) and (Write(NewValue, 4) = 4); finally Free; end; end;
Filename is the table you would like to set a new AutoInc value.
NewValue is the new AutoInc value you would like to assign.
To reset a tables AutoInc you just need to call the function like this :
If you need to read the current value of the AutoInc field (not the value of the last record) you could use this function:
function ReadAutoInc(FileName: TFileName): Longint; var st : TFileStream; Buffer : Longint; begin st := TFileStream.create(FileName,fmOpenread + fmShareDenyNone); st.Seek(73, soFromBeginning); st.ReadBuffer(Buffer, 4); st.Free; Result := Buffer; end;
This function returns an integer number with the current AutoInc value hard-coded into the table.
Call the function like this :
Thats all folks…………..