Solved

Creating database aliases in code

Posted on 1998-03-07
4
441 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

740 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