c++ - qt simultaneous MySQL queries in different threads = crash -


I have written a multi-layered QT5 app that is written in C ++, where each thread is written in the same database. Used to be.

I share the database QSqlDatabase variable similar to a thread, but each thread creates its query I'm crashing regularly and I have taken this information in the time of an accident: driver error [QVMSQL 3: Unable to store results of statement] Database error [coming out of sync; You can not run this command anymore] Type [2] number [2014]

First of all, can I query mysql together in multiple sources simultaneously? If so, do I need to protect the SQL call with a Mute X? Or I need to post more information ....


UPDATE: I have a separate DBManager thread which manages to open / close DB, and writes simple database. I did this because my db used to go offline, and I do not want the second thread to last for 2 minutes, while a db open fails. No, I have more threads that report, and DB should recover enough data.

As mentioned below, sharing the DB handle on the thread is not allowed. So now maybe it's more of a design question - what's the best way to handle this situation? I do not want every thread that tries to open DB's access to itself and wait for 2 minutes when DB is offline.

Read the documentation for the SQL module, in particular, indicating that each connection can be used only within the thread that it was created.

So there is not enough to add a mute x, you will either need to create a new connection object in each thread, or pass the required data to a dedicated thread that all DB queries. >

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -