Solved

Creating database aliases in code

Posted on 1998-03-07
4
439 Views
Last Modified: 2010-04-06
With the following code snippet I am try to create a database alias in code:

procedure TLogData.LogDataCreate(Sender: TObject);
Var
MakeAlias : TDataBase;
Directory : String;
begin
Directory := GetCurrentDir + '\LogTables';
MakeAlias := TDataBase.Create(LogData);
 With MakeAlias do begin
 DatabaseName := 'Logbook';
 DriverName := 'STANDARD';
 Params.Clear;
 Params.Add('Path=' + Directory);
 KeepConnection := True;
 LoginPrompt := True;
 end;
 tblLog.DatabaseName := 'Logbook';
 end;

When I run the program it will bomb out and give me an error saying:
An error has occured while attempting to initialize the borland database engine (error $2A06).

But when I pass the directory directly to the Params.Add as follows:

Params.Add('Path=d:\Logbook\LogTables');

it will work.

So I guess may question is why does it not work when I try to pass a concantenated string to the Params.Add.....
 
0
Comment
Question by:delbrad
4 Comments
 
LVL 5

Expert Comment

by:inter
ID: 1360243
Hi friend,

Did you try the variations such as

Format('Path=%s',[Directory]);

I think the problem of creation of Delphi internal strings and their transfer to the BDE on DLL interface.

If you are there please notify,
Igor


0
 

Accepted Solution

by:
pmaartense earned 50 total points
ID: 1360244
First: what is the current directory? is the program running in the same directory as you want your database to be located?


Better to use is the following code:

Directory := ExtractFilePath(Application.Exename)+'\logtables';

This will ALWAYS point to the directory where te execuatbel is located (even over UNCpath) and then add the subdir to the var.
0
 

Author Comment

by:delbrad
ID: 1360245
I have tried the Fomat and the ExtractFilePath function and sadly they do not work I guess this is just another one of the many delphi bugs...


0
 

Expert Comment

by:wtamviset
ID: 1360246
This is easy way to create standard database alias in your code by using TSession Object.
procedure AddStandardAlias(const Name, Path, DefaultDriver: string);
Example:
  Session.AddStandardAlias('DB_PERSONAL','c:\data\person','Paradox');

You don;t need to create Session Object , it will be created by delphi automatic.  

0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question