I’m not 100% shure, but I see an Error from time to time.
I’m preparing MySQL Statements with ne “new” syntax (selectsql(“SELECT * FROM table WHERE id = ?”, rowid)
Sometimes I get an DatabaseException wit ErrorNumber -1 and Message Expected 0 parameters to be bound but received 1
“Expected 0” is definetly wrong, abd “normally” these queries are correct and working. In debugger everything seems fine.
I suspect that in reality the connection to the database is closed (timeout), but then I would expect an error 2006 or 2013.
Is there anyone who can reproduce this or has already had the error?
set a timer in the app properties that makes a simple query like select(1) each 5-10 mins or so to maintain the connection to the server
or
if there is an error like this one, try to reconnect once to the database then do the query again. if there is no error this time, then it is a connection timeout and you can use the query result again.
I had something like this with a postgres database (long ago) …
The error message about the number of parameters is incorrect - I see this frequently, sometimes any database error is reported this way. Issue 73351, maybe fixed in 2023R2.
MySQL will time out inactive connections - this is coming from the MySQL server. I retry once on any error, this solves the problem. A second exception indicates something is actually wrong, though the error message might not be helpful.
I had to fight with this a few years ago as well. Since then i just do a db.Connect before i start my db-work. Those connects happen so fast even with a secured connection, i do not fight with timeouts anymore…
Yes, correct. but I don’t want to reconnect on ANY error. There are errors, where you should just reconnect and there are errors, where you don’t. Nearly everything is a workaround for bugs. I don’t think, this Error -1 is comeing from MySQL.
It’s definitely not as fast as not establishing a new connection. But I create program-internal caches wherever sensible and possible and I share database connections wherever possible. With the latter, of course, I always have to make sure that a connection is never used by 2 or more objects at the same time.
A lot of things are temporarily stored in the program so that the user can work undisturbed. When the user leaves the current program area, the data is exchanged with the servers in threads. So far I’ve managed it so elegantly that users feel like they’re working with local data.
But I agree, if you can avoid reconnecting, it’s probably better to avoid it.