Solved

Creating database aliases in code

Posted on 1998-03-07
4
437 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

762 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now