delphi3000.com - the free delphi knowledge platform
delphi3000.com - the free delphi knowledge platform
499 Users Online NOW
Have a look at your member-status

connecting people's knowledge


  - Recent ArticlesRSS feed for Recent Articles on delphi3000.com
  - List of All Articles
  - Top Viewed Articles
  - Articles (+Attachem.)
  - Articles Of Interest
  - Categories
  - Top Uploader
  - Search
  - Index

  - My Home
  - Submit an Article
  - My Articles
  - My Personal Data
  - My Bookmarks
  - Activities
  - Login/Logout

  - Sign Up
  - Why Sign Up
  - Newsletter

  - Press
  - Advertise

  - Contact
  - Feedback





Community
Borland
ClubeDelphi
Dr. Bob
UK-BUG
Delphi Meetings
Planeta Delphi



Loremo - the 1.5 liter car coming in 2009




Startblatt.de






Share this article with friendsShare this article with friends
Rate this articleRate this article - to keep the quality of delphi3000.com !
Comment this article or read through previous comments (0)


BDE Safe Configuration checkGo to <B>Erwin</B> Molendijk's websiteFormat this article printer-friendly!Bookmark function is only available for registered users!
Product:
Delphi 5.x (or higher)
Category:
BDE
Skill Level:
Scoring:
Last Update:
11/27/2001
Search Keys:
delphi delphi3000 article borland vcl code-snippet BDE PrivDir LocalShare local share NetDir net dir safe corruption network multi user
Times Scored:
2
Visits:
4865
Uploader: Erwin Molendijk
Company: Carvix & Delfer
Reference: N/A
 
Question/Problem/Abstract:
Running the BDE in a safe mode requires some settings in the BDE Administrator tool. This unit checks if the BDE has been configured correctly (LocalShare=True, NetDir=\\...). Also the PrivDir will be managed by this unit, a unique PrivDir will be created and cleaned up every time the (your) program is run.
Answer:



unit modBDETools;

{ module Borland Database Engine Tools
  Author: E.J.Molendijk
  Mail: erwin@delphi-factory.com

  When this unit is linked into the project the PrivDir of
  the global Session variable will be set to a
  unique directory within the (local) system temp dir.
  When the application ends, this private dir
  will be cleaned up.
  
  Also a routine CheckBDEConfig() can be called to check if the
  BDE is configured for safe opperation.


Hint, for best performance set the BDE to:

  Setting                             Value
  -------------------------------------------------------------
  \System\INIT\LANGDRIVER             'ascii' ANSI (DBWINUS0)
  \System\INIT\MAXBUFSIZE             16384 KB
  \System\INIT\MINBUFSIZE             128 KB
  \System\INIT\MAXFILEHANDLES         100
}


interface

uses
  DB, DBTables, BDE, SysUtils, Windows, FileCtrl, ComObj;


{ This function returns True if the BDE is configured
  with a NetWork directory with an UNC path (\\server\share)
  and has LocalShare set to True.
  The Msg param will be filled with a msg describing the problem. }
function CheckBDEConfig(var Msg : String) : Boolean;

implementation

const
  { Here are the parameters used to pass into the cfg functions.  These are only
    a small portion of what types can be passed in.  You need to call
    DbiOpenCfgInfoList with '\' into pszCfgPath to get all possible options if
    it is not found below. }

  { Paradox Driver Settings...  }
  PARADOXNETDIR = '\DRIVERS\PARADOX\INIT\;NET DIR';
  PARADOXVERSION = '\DRIVERS\PARADOX\INIT\;VERSION';
  PARADOXTYPE = '\DRIVERS\PARADOX\INIT\;TYPE';
  PARADOXLANGDRIVER = '\DRIVERS\PARADOX\INIT\;LANGDRIVER';
  PARADOXLEVEL = '\DRIVERS\PARADOX\TABLE CREATE\;LEVEL';
  PARADOXBLOCKSIZE = '\DRIVERS\PARADOX\TABLE CREATE\;BLOCK SIZE';
  PARADOXFILLFACTOR = '\DRIVERS\PARADOX\TABLE CREATE\;FILL FACTOR';
  PARADOXSTRICTINTEGRITY = '\DRIVERS\PARADOX\TABLE CREATE\;STRICTINTEGRITY';

  { System Initialization Settings...  }
  AUTOODBC = '\SYSTEM\INIT\;AUTO ODBC';
  DATAREPOSITORY = '\SYSTEM\INIT\;DATA REPOSITORY';
  DEFAULTDRIVER = '\SYSTEM\INIT\;DEFAULT DRIVER';
  LANGDRIVER = '\SYSTEM\INIT\;LANGDRIVER';
  LOCALSHARE = '\SYSTEM\INIT\;LOCAL SHARE';
  LOWMEMORYUSAGELIMIT = '\SYSTEM\INIT\;LOW MEMORY USAGE LIMIT';
  MAXBUFSIZE = '\SYSTEM\INIT\;MAXBUFSIZE';
  MAXFILEHANDLES = '\SYSTEM\INIT\;MAXFILEHANDLES';
  MEMSIZE = '\SYSTEM\INIT\;MEMSIZE';
  MINBUFSIZE = '\SYSTEM\INIT\;MINBUFSIZE';
  SHAREDMEMLOCATION = '\SYSTEM\INIT\;SHAREDMEMLOCATION';
  SHAREDMEMSIZE = '\SYSTEM\INIT\;SHAREDMEMSIZE';
  SQLQRYMODE = '\SYSTEM\INIT\;SQLQRYMODE';
  SYSFLAGS = '\SYSTEM\INIT\;SYSFLAGS';
  VERSION = '\SYSTEM\INIT\;VERSION';

type
  pword = ^word;

function GetBDEConfigParameter(Param: string; Count: pword): string;
var
  hCur: hDBICur;
  rslt: DBIResult;
  Config: CFGDesc;
  Path, Option: string[254];
  Temp: array[0..255] of char;

begin
  Result := '';
  hCur := nil;

  if Count <> nil then
    Count^ := 0;

  try

    if Pos(';', Param) = 0 then
      raise EDatabaseError.Create('Invalid parameter passed to function.  There must ' +
         'be a semi-colon delimited sting passed');

    Path := Copy(Param, 0, Pos(';', Param) - 1);
    Option := Copy(Param, Pos(';', Param) + 1, Length(Param) - Pos(';', Param));

    Check(DbiOpenCfgInfoList(nil, dbiREADONLY, cfgPERSISTENT, StrPCopy(Temp, Path), hCur));
    Check(DbiSetToBegin(hCur));

    repeat
      rslt := DbiGetNextRecord(hCur, dbiNOLOCK, @Config, nil);
      if rslt = DBIERR_NONE then
      begin
        if StrPas(Config.szNodeName) = Option then
          Result := Config.szValue;
        if Count <> nil then
          Inc(Count^);
      end
      else
        if rslt <> DBIERR_EOF then
          Check(rslt);
    until rslt <> DBIERR_NONE;

  finally
    if hCur <> nil then
      Check(DbiCloseCursor(hCur));
  end;
end;

procedure PrepareBDEPrivDir;
{
  The PrivDirID constant is used to create the Session.PrivDir
  Complete private path:  TempPath\PrivDirID\RandomStr

  The RandomStr (GUI) will ensure a unique path every time the
  program is started.
  The PrivDirID can be used (by batchfile) to delete all junk RandomStr's
  left over from abnormal program terminations.

  Note: CleanupBDEPrivDir cleans up the dir created by this routine.
}
const
  PrivDirID = 'CharonPrivDir';
var
  Temp : string;
  I : Integer;
begin
  // Get a temp directory name for private dir
  I := GetTempPath(0,pchar(Temp)); // get length
  SetLength(Temp,I);  // prepare for this length
  GetTempPath(I,pchar(Temp)); // retreive temp path
  SetLength(Temp,I-1);  // remove #0
  Temp := IncludeTrailingBackSlash(Temp); // inlcude a trailing slash

  // construct a unique temppath
  Temp := Temp+PrivDirID+'\'+CreateClassID;

  // create the directory
  ForceDirectories(Temp);

  // Set the PrivDir
  Session.PrivateDir := Temp;

//  ShowMessage('Private directory: '+Temp);
end;

procedure CleanupBDEPrivDir;
{ Cleansup the Private dir.
  (all database connections will be closed!)
}
var
  CleanUpOK : Boolean;
begin
  // Close the session -- this will empty the PrivDir
  Session.Close;

  // Remove the PrivDir
  CleanUpOK := RemoveDir(Session.PrivateDir);

  Assert(CleanUpOK);
end;

function CheckBDEConfig(var Msg : String) : Boolean;
const
  strTrue = 'TRUE'; { do not localize }

var
  NetDir, LocalShare : String;

begin
  // Get BDE settings
  NetDir := GetBDEConfigParameter(PARADOXNETDIR,nil);
  LocalShare := Uppercase(Trim(GetBDEConfigParameter(modBDETools.LOCALSHARE,nil)));

  Msg := '';

  if Pos('\\',NetDir) <> 1 then
    Msg := 'Set the NetDir option in the BDE Administrator to an UNC path.';

  if LocalShare <> strTrue then
    Msg := 'Set the LocalShare option in the BDE Administrator to TRUE.';

  // Check them
  Result := Msg='';
end;


initialization
  PrepareBDEPrivDir;

finalization
  CleanupBDEPrivDir;

end.





Please rate this article!
Skill level:
BeginnerExpert

Useful:
No!Very!

Overall rating:
PoorExcellent



Comments to this article
Write a new comment













 
Sign up to consume product discounts for Bronze memberships !

read more


  Visit our Sponsor

 

  Community Ad of
E. DSpirito
 
   














 







     
  Copyright © 2000 - 2007 delphi3000.com - All rights reserved. Terms of use. || Privacy
delphi3000.com is a service by bluestep.com IT-Services GmbH (Vienna)