Key violation in networked Paradox table

Key violation in networked Paradox table

I have installed a Delphi 2.0 BDE application over a network where two terminals can access the table at the same time.

I have checked the NET DIR to point to shared directory on both terminals. However, after several operations, the application complains ‘KEY VIOLATION’.

I have suspected that the problem is caused by an autoincrement field(+) because if I delete the field and then re-create it, it goes back to normal.

What should I do? Make my own AutoIncrement procedure?

That’s a really strange problem. AutoIncrement fields are “supposed” to be unique because there’s internal error checking in the BDE to make sure thereare no duplicates, but you never know. As to making your ownAutoIncrement procedure, that’s exactly what I do, primarily because Iwant total control of my data. AutoIncrement fields, while convenient, taketoo much control away. But I tend to be paranoid about that stuff.

The typical methodology for creating your own keys is to create a separate table that has a single field of type integer or float (depending uponyour needs), and a single row. Here’s a function that gets the key from a keytable:

function GetKey(KeyTblName, KeyFldName : String) : LongInt;var  tblKey : TTable;begin  tblKey := TTable.Create(Application);  with tblKey do begin    Active := False;    repeat { until successful or Cancel button is pressed }      try        Exclusive := True; { See if it will open }        Active := True;        Break;      except on EDatabaseError        {You can put code in here to abort if you want.         Otherwise, this will loop until it can get exclusive access.}      end;    until False;            Edit;    Result := FieldByName(KeyFldName).AsInteger;    Result := Result + 1;    FieldByName(KeyFldName).AsInteger := Result;    DbiSaveChanges(Handle);    Free;  end;end;
This function will increment the key value in the table and return the result, which you can add to your application. For example, here’s how you’duse it:
procedure AddNewRecord;begin  with Table1 do begin    if (State <> dsEdit) then      Edit;    Append;    FieldByName(‘MyKeyField’).AsInteger := GetKey(‘KeyTable.DB’, ‘KeyFld’);  end;end;
The disadvantage of this is that you have to make sure that you don’tduplicate keys in your application. But then again, you have total controlover how this works.

Share the Post:
XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several

data fivetran pricing

Fivetran Pricing Explained

One of the biggest trends of the 21st century is the massive surge in analytics. Analytics is the process of utilizing data to drive future decision-making. With so much of

kubernetes logging

Kubernetes Logging: What You Need to Know

Kubernetes from Google is one of the most popular open-source and free container management solutions made to make managing and deploying applications easier. It has a solid architecture that makes

ransomware cyber attack

Why Is Ransomware Such a Major Threat?

One of the most significant cyber threats faced by modern organizations is a ransomware attack. Ransomware attacks have grown in both sophistication and frequency over the past few years, forcing

data dictionary

Tools You Need to Make a Data Dictionary

Data dictionaries are crucial for organizations of all sizes that deal with large amounts of data. they are centralized repositories of all the data in organizations, including metadata such as