How to close mysql connections?

Forum for posting problems using QxOrm library

How to close mysql connections?

Postby behtgod » Tue Nov 22, 2016 8:38 am

For example,I insert data into mysql database with multithread.
In each thread,I call
qx::dao::insert()
.
This will create some connection to connect the database for insert operation,of cause.
But, these connection never been closed until the application shutdown.
That make me a trouble because the connection has a max limit.
Is there had function to close the connection?
behtgod
 
Posts: 18
Joined: Mon Nov 16, 2015 8:21 am

Re: How to close mysql connections?

Postby qxorm » Tue Nov 22, 2016 10:05 am

Hello,

Is there had function to close the connection?

Yes of course.
To get the connection to database for current thread and close it, just write this code :
Code: Select all
QSqlDatabase db = qx::QxSqlDatabase::getDatabase();
db.close();


QSqlDatabase is a Qt class, the documentation is here : http://doc.qt.io/qt-5/qsqldatabase.html
About QxOrm qx::QxSqlDatabase class, there are some details in the QxOrm manual here : http://www.qxorm.com/qxorm_en/manual.html#manual_310
qxorm
Site Admin
 
Posts: 481
Joined: Mon Apr 12, 2010 7:45 am

Re: How to close mysql connections?

Postby behtgod » Wed Nov 23, 2016 3:10 am

qxorm wrote:Hello,

Is there had function to close the connection?

Yes of course.
To get the connection to database for current thread and close it, just write this code :
Code: Select all
QSqlDatabase db = qx::QxSqlDatabase::getDatabase();
db.close();


QSqlDatabase is a Qt class, the documentation is here : http://doc.qt.io/qt-5/qsqldatabase.html
About QxOrm qx::QxSqlDatabase class, there are some details in the QxOrm manual here : http://www.qxorm.com/qxorm_en/manual.html#manual_310


Thank you very much!
behtgod
 
Posts: 18
Joined: Mon Nov 16, 2015 8:21 am


Return to QxOrm - Help

Who is online

Users browsing this forum: No registered users and 1 guest

cron