Managing multiple database connections

Forum for posting problems using QxOrm library

Managing multiple database connections

Postby marat » Fri Oct 26, 2012 5:58 pm

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.
marat
 
Posts: 15
Joined: Tue Jul 17, 2012 8:23 pm

Re: Managing multiple database connections

Postby qxorm » Sun Oct 28, 2012 10:40 am

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
qxorm
Site Admin
 
Posts: 481
Joined: Mon Apr 12, 2010 7:45 am


Return to QxOrm - Help

Who is online

Users browsing this forum: No registered users and 10 guests

cron