|
-
Feb 26th, 2005, 08:09 AM
#1
Thread Starter
Lively Member
Inline Code/Class Question [Resolved]
Hi,
I'm creating a database application, which connects to a database and performs different queries on different forms. I've designed it two different ways:- Using code in each form to make a new connection and then doing the query with that
- Using a class for the connection, and creating a global instance of it in a module, so that the connection is made when the application loads and the recordset is accessed by various Property Get statements.
Which do you think is better programming practice? Generally, we're encouraged not to use global declarations, but this is an object, so I'm not sure if that's okay. Also, with the class, if I need to retrieve some information from a separate table (e.g. I have an ID number from one table, and I need to match that to a name from another), then I either have to store the orginal query and query again at the end of retrieving the new information, or create a new instance of the class.
If this is unclear, and you want some code, just ask.
Last edited by olamm2k; Feb 26th, 2005 at 03:37 PM.
-
Feb 26th, 2005, 12:12 PM
#2
Thread Starter
Lively Member
Re: Inline Code/Class Question
Had another thought on this since earlier:
What if I declared my connection object globally when the application starts and then created separate recordsets each time I needed them?
There must be some standard way of doing this...
-
Feb 26th, 2005, 02:45 PM
#3
Re: Inline Code/Class Question
 Originally Posted by olamm2k
Hi,
I'm creating a database application, which connects to a database and performs different queries on different forms. I've designed it two different ways: - Using code in each form to make a new connection and then doing the query with that
- Using a class for the connection, and creating a global instance of it in a module, so that the connection is made when the application loads and the recordset is accessed by various Property Get statements.
Which do you think is better programming practice? Generally, we're encouraged not to use global declarations, but this is an object, so I'm not sure if that's okay. Also, with the class, if I need to retrieve some information from a separate table (e.g. I have an ID number from one table, and I need to match that to a name from another), then I either have to store the orginal query and query again at the end of retrieving the new information, or create a new instance of the class.
If this is unclear, and you want some code, just ask.
#2 is definately more Object-Oriented than #1 so I would strongly recommend #2.
However there is a third option, which is similar to #2; make #2 as an ActiveX EXE (out of process Object). This object would be stand-alone, running before and/or after your application loads. This gives you the advantages of encapsulation and the option to run the Object on your machine, or even a centralized server (a different machine).
Nobody knows what software they want until after you've delivered what they originally asked for.
Don't solve problems which don't exist.
"If I had eight hours to cut down a tree, I'd spend six hours sharpening my axe." --- Abraham Lincoln (1809-1865)
2 idiots don't make a genius.
-
Feb 26th, 2005, 02:56 PM
#4
Thread Starter
Lively Member
Re: Inline Code/Class Question
Thanks for your reply.
I've not created an ActiveX EXE before, so I've no idea how to go about this (not the creation, but how to use it once made).
Could you give me an example, or point me to a site containing one?
-
Feb 26th, 2005, 03:01 PM
#5
Re: Inline Code/Class Question
Either technic will work, it does however totally depends on your application architecture. If you don't need to keep connection open then why would you ever need to declare ti globally and visa versa ... You may get tons of recommendation but it's all your call - you're the designer so you must know all aspects ... There is however one thing to keep in mind: simplicity is what really counts after all - don't overcomplicate you program(s) if there is no need for it ...
Cheers
-
Feb 26th, 2005, 03:08 PM
#6
Thread Starter
Lively Member
Re: Inline Code/Class Question
The connection will be kept open the whole time, which is why I think it makes sense to just create it once, then make the various recordsets I need from it.
Do you think a class approach would be better, or just declaring it in a module as a global object (Global objConn as New ADODB.Connection etc.)?
-
Feb 26th, 2005, 03:12 PM
#7
Re: Inline Code/Class Question
Personally I don't think that class is necessary: it will create some overhead - object within object.
Declaring ONE object variable as adodb.connection globally in the module should be more than enough.
-
Feb 26th, 2005, 03:17 PM
#8
Thread Starter
Lively Member
Re: Inline Code/Class Question
Fair enough - I'll go with the global object declaration.
Just out of interest, though, how do you use an ActiveX EXE as suggested?
-
Feb 26th, 2005, 03:31 PM
#9
Re: Inline Code/Class Question
How would you use it as suggested ? That would be for creating DCOM type applications.
You may want to visit MSDN ON LINE for more information.
Good luck.
-
Feb 26th, 2005, 03:36 PM
#10
Thread Starter
Lively Member
Re: Inline Code/Class Question
Thanks, I'll take a look.
-
Feb 26th, 2005, 03:53 PM
#11
Re: Inline Code/Class Question
 Originally Posted by olamm2k
Fair enough - I'll go with the global object declaration.
Just out of interest, though, how do you use an ActiveX EXE as suggested?
This may be a good place to start:
http://www.vbforums.com/showthread.php?t=306032
Nobody knows what software they want until after you've delivered what they originally asked for.
Don't solve problems which don't exist.
"If I had eight hours to cut down a tree, I'd spend six hours sharpening my axe." --- Abraham Lincoln (1809-1865)
2 idiots don't make a genius.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|