Sorting Out Lock Files Once and For All!
by Matt Hamilton - MHamilton@bunge.com.au
Every once in a while I've had the old "Lock file has grown too large" or "Directory is controlled by another .net file" errors. Very frustrating. So I did some reading, and came up with a solution.
The Delphi help file says that you should use the Session.NetFileDir and Session.PrivateDir properties to control where paradox puts its lock files. It recommends that, for network applications, NetFileDir be the same directory as the executable, and that PrivateDir be a local directory.
This is incorrect in two ways: Firstly, if you are running your application from a network drive, say
Thus, the NetFileDir should really sit in the database directory "F:\MyApp\MyData\", to ensure that the users have full access to it.
Secondly, if the user runs more than one Paradox application concurrently, and both use the same local directory, say
Well, here's my solution. First, put this in your Datamodule's OnCreate event:
{ Close all active tables and reseat
the lock files }
with Session do
begin
Close;
NetFileDir := DataPath;
{ Find a temporary
dir for PrivateDir, and make a subdirectory under that! }
GetTempPath(1023,
TempPath);
PrivateDir := StrPas(TempPath)
+ '\' + Table1.DatabaseName;
if not DirectoryExists(PrivateDir)
then
CreateDir(PrivateDir);
end;
// Open the tables
Table1.Open; Table2.Open; // etc...
end;