Page 1 of 1

Managing multiple database connections

PostPosted: Fri Oct 26, 2012 5:58 pm
by marat
1. What is the preferred way to manage several database connections from an application?

2. Is it possible to keep multiple connections open at the same time?

3. After finishing with a database connection, how should I initialize the next connection?

For example. the code connects to 1 database using the typical QxSqlDatabase::set...() methods. Next I try to do it initialize
to another DB using the same sequence of steps, but execution of queries fail. I also tried to close the db after being done initially and
re-initialize again using QxSqlDatabase::set...() - doesn't work either.

Re: Managing multiple database connections

PostPosted: Sun Oct 28, 2012 10:40 am
by qxorm
Hi,

Each function provided by QxOrm library to access to database has an optional parameter : QSqlDatabase * pDatabase = NULL (for example, see qx::dao functions : http://www.qxorm.com/doxygen/html/names ... _1dao.html).
If you keep the default value (NULL), then QxOrm manages automatically the connection to database using qx::QxSqlDatabase singleton.
If not NULL, then you can easily define by yourself multiple connections to differents databases and then pass a pointer of type QSqlDatabase (from Qt library) to each function (you can create for example a pool of connections to databases)...

More details about QSqlDatabase on Qt website : http://doc-snapshot.qt-project.org/4.8/ ... abase.html