Which of MultiStatements is "out of sync" How do I find out which statement is out of sync when I get error 2014 with Multi-Statements? 

I am calling libmysql.mysql_query with a SQL Connection with SupportsMultiStatements, passing a string of commands separated by ;.
This code runs all day without errors.  But every few days (with no regularity) my application throws:


  2014 - Commands out of sync; you can't run this command now.


Retry always works.

The error message does not specify which of the multiple commands is "out of sync".  Is there any way to know?

This question is not how to fix my specific problem, so I haven't included the list of commands. (I suspect the intermittent problem is caused by a timeout waiting for table lock.)  This question is about how error 2014 applies to multi-statements.
Usually that refers to Stored routines with PREPARE + EXECUTE + DEALLOCATE_PREPARE.  Have you done all three of those, in that order?  Optionally, EXECUTE can be repeated.

If you are referring to stringing together statements with ;, don't do that; it is a security hole waiting for some hacker to jump into.

What client language are you using?

If you need more help, let's see your code.