Solved

Creating database aliases in code

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

Industry Leaders: 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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

729 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