Its mentioned in the user manual:
"An important limitation of the MySQL C API library - which MySQL++ is
built atop, so it shares this limitation - is that you can't have two
concurrent queries running on a single connection. If you try, you get an
obscure error message about "Commands out of sync" from the underlying C API
library. (You get it in a MySQL++ exception unless you have exceptions
disabled, in which case you get a failure code and Connection::error()
returns this message.)"
However I am not running concurrent queries on a single connection. All I
want to do is the following( the example is stripped of some details )
conn=l_cpm->rtGrab(); // returns the most recently
used connection not in use now
mysqlpp::StoreQueryResult res =
q.store(); // This throws exception i.e out of sync
catch(const mysqlpp::Exception& e)
cout<<"\n********Unknown exception thrown"<<endl;
Here I am using a single connection to execute queries, however they are not
being used concurrently as is evident from the code. However it is still
throwing out of sync exception from the store( ) function.
Does this mean that once a connection has been used to execute one query, we
need to close it ? Then this would essentially make a connectionpool
The above code doesn't use the connection pool functionality and is just to
highlight the problem I am facing. Here is the description of the problem I
Thread1 takes a connection from the pool and executes a query and releases
Thread2 now takes a connection from the pool and executes a query( the same
query). If the connection pool returns the most recently used connection,
then the connection received by thread2 is the same that was released by
thread1 and since thread1 has already used it to execute 1 query on that
connection, when thread2 tries to execute its query it throws out of sync
The above query is a procedure.
I guess I am missing something or else this would be a major flaw. If I am
missing something kindly provide some code snippet of trying to execute a
procedure using cpm.
In the connection class its mentioned:
Return a new query object.
The returned query object is tied to this connection object, so when you
call a method like execute()
that object, the query is sent to the server this object is connected to.
Does the problem has anything to do with above ?