XML Posted March 20, 2018 Share Posted March 20, 2018 Hello, I got this weird problem, [Expected db-connection at argument 1] The script was working fine for a long time, but suddenly this error appeared. So when i get this error, I restart the resource, And then it works, And the same problem appears again after a while. Did someone got the same problem before ? Help. Link to comment
MIKI785 Posted March 20, 2018 Share Posted March 20, 2018 The connection could have timed out. If there is no query for some time period (usually around 20-30 minutes) then the (My)SQL server closes the connection. Link to comment
XML Posted March 20, 2018 Author Share Posted March 20, 2018 So i have to put an (if) statement ? To check whether is there a connection or not ? And if not, I make a new connection ? Link to comment
MIKI785 Posted March 20, 2018 Share Posted March 20, 2018 Yes, or if you do a lot of queries, then make your own query function and stick the condition in there so you don't have to repeat the same thing everywhere. Link to comment
XML Posted March 20, 2018 Author Share Posted March 20, 2018 Can you give an example for that ? Link to comment
MIKI785 Posted March 20, 2018 Share Posted March 20, 2018 (edited) I suppose you use dbQuery, so: _dbQuery = dbQuery --store the original func function dbQuery (connection, ...) local arg = {...} if not connection then connectionGlobal = dbConnect() --fill it in and change connectionGlobal to wherever you store the connection connection = connectionGlobal end _dbQuery(connection, unpack(arg)) end Note that this won't work if you use callbacks in dbQuery as it expects the first argument to be the connection. Also, didn't test this. Edited March 20, 2018 by MIKI785 Forgot to use the original func.. 1 Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now