Solved

Creating database aliases in code

Posted on 1998-03-07
4
438 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
add combobox item based on numbers 9 144
Using idhttp to login to instagram 2 91
Performance of SQL statement 37 112
Delphi: sending SMS on android platform 1 21
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

832 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