Howdy,
Can someone tell me the best way to do this. I'm trying to make a simple database app, view, add, edit, delete records etc. Is it best to open the connection when the programme is first run, and close the connection when the programme is closed. Or, should the connection be opened only when it is needed - to run an SQL query, and then closed immediately?
I assume leaving the connection open uses up system resources, however open and closing frequently takes time. So which is best?
Cheers,
~Adam
Posted on 2002-09-19 05:55:55 by adamjjackson
www.win32asm.cjb.net / Tutorials / ODBC
Posted on 2002-09-19 06:15:20 by bazik
Hi,
Thanks, but that doesn't really answer my question. I know how to make connections etc, I was wondering which is more efficient. Keeping the connection open for a long time, or making the connection frequently?
Cheers.
Posted on 2002-09-19 08:09:30 by adamjjackson
Sorry, I didnt read your complete post :stupid:

If possible, you should keep the connection open.
Posted on 2002-09-19 10:25:28 by bazik
it will mainly depend on your "backbone" database software. Most DBMS have a connection timeout (f.e. 3 minutes)
after that the connection will be closed. I think, if you connect local, closing connections immediatly will be better.
With remote access, especially over internet, it could be a problem, to re-connect, so leaving connection open will be
better.

Often you find also a maximum-connection value. So if some other users need also to connect to the DBMS, it would be
"polite" to close the connection as fast as possible.

However, the best way is to encapsulate all operations into transactions, so between two transactions is not many
to do, if a reconnect is neccessary.
Posted on 2002-09-19 10:58:51 by beaster
It's only a really simple programme, just the one user at any one time, so only one connection. Would you still recommend closing the connection?
Cheers again,
~Adam
Posted on 2002-09-19 11:52:29 by adamjjackson
No, don't close the connection. The system resources that you use when you have a connection open are only minimally more than when you don't have a connection open, because you already have the database drivers etc loaded into memory no matter what state the connection is in.

With the capabilities of pc's these days, i would not worry about being a "resource hog". In quite a karmic fashion, you are making up for any waste of resources you incur with an open db connection by writing your app in asm. How poetic :)
Posted on 2002-09-20 07:28:02 by sluggy
Lol, okay, it's all about learning though (the asm bit). Even more reason to try and reduce the resources I use then!! ASM does have it's advantages though - everything is free, I can't learn a HLL because the compilers etc all cost, so in economic terms it's saving me too.
Anyway, thanks,
~Adam
Posted on 2002-09-20 09:15:31 by adamjjackson
For your information, there exist many free compilers all around for nearly all langages :

C/C++ : - GCC (many langages, including C/C++ : www.mingw.org
- Free Commandline tools (from Borland website)

And even a free version of Delphi : here for Pascal...
Posted on 2002-09-20 09:31:33 by JCP