BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Best practices for datbase connection?

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> comp.lang.pascal.delphi.databases
View previous topic :: View next topic  
Author Message
Guest






PostPosted: Wed Oct 18, 2006 4:47 pm    Post subject: Best practices for datbase connection? Reply with quote



Hi,

I am currently writing an application in Delphi 5 which is supposed to
connect to and diagnose Access databases using BDE. Since I am an
inexperienced Delphi programmer I was hoping that you could help me out
by sharing your best practices with me concerning database interaction.

Where to put database connection?
My initial thought is to put the database connection in the main form.
Creating and opening it in the constructor, destroying and closing in
the destructor.

Where to put DataSources?
Since many DataAware controls can connect to the same DataSource it
seems to me that it belongs in a DataModule?

How many DataModules?
Should I use one big DataModule for all Querys and DataSources or
should I have one DataModule for each pair of them or maybe something
in between?

How to connect Querys to database?
As I have understood this is just a matter of using the same database
name for the connection as well as the Queries?

How to change database on the fly?
Just change the alias for the connection?

A lot of questions, hope you can bare with me. I have little time, no
expertise around and want to get it right and write good code.
Back to top
Dan
Guest





PostPosted: Wed Oct 18, 2006 7:54 pm    Post subject: Re: Best practices for datbase connection? Reply with quote



On 18 Oct 2006 04:47:26 -0700, MorrganMail (AT) gmail (DOT) com wrote:

Quote:
Hi,

I am currently writing an application in Delphi 5 which is supposed to
connect to and diagnose Access databases using BDE. Since I am an
inexperienced Delphi programmer I was hoping that you could help me out
by sharing your best practices with me concerning database interaction.

Where to put database connection?
My initial thought is to put the database connection in the main form.
Creating and opening it in the constructor, destroying and closing in
the destructor.

Put them in a DataModule
Quote:

Where to put DataSources?

Put them in the same DM

Quote:
Since many DataAware controls can connect to the same DataSource it
seems to me that it belongs in a DataModule?

Yes
Quote:

How many DataModules?
Should I use one big DataModule for all Querys and DataSources or
should I have one DataModule for each pair of them or maybe something
in between?

As many as you need Wink I like to keep the total number of lines in the

unit below a few hundred, so it is easier to find things. The form can
have quite a few objects on it, such as queries, data sources, etc. as
long as there isn't much code associated with them. It makes no
difference in the final executable size or the processing speed. Make
it easy on yourself.

Quote:
How to connect Querys to database?
As I have understood this is just a matter of using the same database
name for the connection as well as the Queries?

Yes. Using the BDE to connect, which is probably what you will start
with, drop a TDatabase object on your dm, give it a meaningful name,
say dbMain. Then drop a TQuery object on the dm. Click the
DatabaseName property in the object inspector, and you should se
dbMain listed. Select it.
Quote:

How to change database on the fly?
Just change the alias for the connection?

Look up TDatabase.DatabaseName in the Help for details. This is a bit
complicated at first. I recommend using an alias for the database; it
makes program development easier because it separates the connection
details from your app. Aliases are set and managed with the
BDEadministrator program which is included in your Delphi software.

If you know in advance what the different DBs are that the user will
connect to, you can use a different alias for each one, and the user
can select the desired one from a list. Your code would then change
the Alias property in the TDatabase object at runtime (while the
connection is closed).
Quote:

A lot of questions, hope you can bare with me. I have little time, no
expertise around and want to get it right and write good code.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> comp.lang.pascal.delphi.databases All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.