• Welcome, Guest. Please login.
 
September 17, 2019, 09:56:12 am

News:

Welcome to the SQLitening support forums!


Handling several database files from one app

Started by Bern Ertl, January 27, 2009, 04:56:48 pm

Previous topic - Next topic

Bern Ertl

January 27, 2009, 04:56:48 pm Last Edit: January 27, 2009, 04:59:36 pm by Bern Ertl
I am designing an application that will need to access several different SQLite/SQLitening database files (remote mode) at various points.

I'm guessing it's only possible to have one database file open at a time unless I use slAttach, is this correct?  I'm not 100% clear on what slAttach does.

Would it be best practice to use slClose to close a database I recently opened and no longer need for immediate processing even if I need to re-open it again shortly, or would there be performance penalties with network traffic for opening and closing the database?

Does slDisconnect automatically close any open database, or does slClose need to be called explicitly?

Fred Meier

QuoteI'm guessing it's only possible to have one database file open at a time
unless I use slAttach, is this correct?  I'm not 100% clear on what
slAttach does.
slAttach will issues the SQL Attach statement after doing password and other
security checking.  This adds another database file to the current
database connection and is the proper and only way you can access more
than one database at the same time.  See http://www.sqlite.org/lang_attach.html

QuoteWould it be best practice to use slClose to close a database I recently
opened and no longer need for immediate processing even if I need to
re-open it again shortly, or would there be performance penalties with
network traffic for opening and closing the database?
No, I would not close and reopen it again "Shortly".

QuoteDoes slDisconnect automatically close any open database, or does slClose need to be called explicitly?
Yes, open databases are automatically closed when you disconnect.  Neither
slClose nor slDisconnect are required. 

From slClose doc:
   Closes the current database handle and sets it to nothing.  This is
   optional.  All databases will be automatically closed when your program
   ends. If you are done with a database but your program will continue to
   run for some time then it is a good idea to close it.

From slDisconnect doc:
   Disconnects from the server.  This is optional.  A connection will
   be automatically disconnected when your program ends. If you are done
   with a connection but your program will continue to run for some time
   then it is a good idea to disconnect.


Bern Ertl

Thanks Fred. 

Just FYI, my app is allowing for the possibility that a client may have the option of connecting to different servers (for instance, a contractor running the client application might be working on projects with different owners - each using their own copy of our system [ie. the server]), so the app needs to explicitly disconnect from the default connection in case they want to reconnect to a different server.