[MySQL] invalid connection handle
#1

I have this wierd problem - as always.

Ofcourse I've searched around for this error, but I can't seem to find the solution anywhere. The "wierd" part is, my script works 9/10 times. All queries are sent and received perfectly, with some exceptions. For example, sometimes on player login, the character is not loaded and hence players spawn as CJ.

The mysql_log I have looks like this:
pawn Код:
[03:53:29] [WARNING] CMySQLConnection::Disconnect - no connection available
[03:53:29] [ERROR] mysql_format - invalid connection handle (id: 1)
[03:53:29] [ERROR] mysql_pquery - invalid connection handle (id: 1)
[03:53:29] [ERROR] mysql_format - invalid connection handle (id: 1)
[03:53:29] [ERROR] mysql_pquery - invalid connection handle (id: 1)
[03:53:29] [ERROR] mysql_format - invalid connection handle (id: 1)
[03:53:29] [ERROR] mysql_pquery - invalid connection handle (id: 1)
[03:53:29] [ERROR] mysql_format - invalid connection handle (id: 1)
[03:53:29] [ERROR] mysql_pquery - invalid connection handle (id: 1)
[03:53:29] [ERROR] mysql_format - invalid connection handle (id: 1)
[03:53:29] [ERROR] mysql_pquery - invalid connection handle (id: 1)
[03:53:29] [ERROR] mysql_format - invalid connection handle (id: 1)
[03:53:29] [ERROR] mysql_pquery - invalid connection handle (id: 1)
[03:53:29] [ERROR] mysql_format - invalid connection handle (id: 1)
[03:53:29] [ERROR] mysql_pquery - invalid connection handle (id: 1)
[03:53:29] [ERROR] mysql_format - invalid connection handle (id: 1)
[03:53:29] [ERROR] mysql_pquery - invalid connection handle (id: 1)
[03:53:29] [ERROR] mysql_format - invalid connection handle (id: 1)
[03:53:29] [ERROR] mysql_pquery - invalid connection handle (id: 1)
-----It goes on like this for 2002 lines.-----
This is what I don't understand... If the connection handle is invalid, how comes the script works almost everytime? The error comes everytime on server restart.

My guess: I do use includes for most of my script. I don't put my commands, functions, stocks etc. in the actual gamemode, but in includes, to keep track of it all.

Does the MySQL plugin initialize/verify every query/format on server start, even when they're not called? The reason why I believe this is that I call mysql_connect on OnGameModeInit and if so, the includes does not have a valid connection handle hence initialized on the top of my script. I tried putting the includes under OnGameModeInit, but it didn't give any result.

Pastebin to full login code: http://pastebin.com/Vv30SVCU

Any ideas on how to fix this?

EDIT: Running ubuntu machine on digitalocean. MySQL is localhost. Should you need any other part of the script, please ask.
Reply
#2

Maybe, adding connection handle on every mysql_ function like ...
Код:
connectionHandle = mysql_connect(HOST, USER, DATABASE, PASSWORD);
mysql_format(connectionHandle, .......);
mysql_tquery(connectionHandle, .......);
Reply
#3

Quote:
Originally Posted by X337
Посмотреть сообщение
Maybe, adding connection handle on every mysql_ function like ...
Код:
connectionHandle = mysql_connect(HOST, USER, DATABASE, PASSWORD);
mysql_format(connectionHandle, .......);
mysql_tquery(connectionHandle, .......);
BlueG's documentation says you only are to initialize one connectionhandle. tquery and pquery should handle the rest and reconnect it if necessary.

Or have I got it wrong?
Reply
#4

As far as I know (I started to study MySQL about 2 weeks ago) it'd be working if you'd add connectionHandle to every function, like X337 already said.
Reply
#5

I use one connection handle under OnGameModeInit, never encountered this.

Which MySQL version are you using?
Reply
#6

Quote:
Originally Posted by itsCody
Посмотреть сообщение
I use one connection handle under OnGameModeInit, never encountered this.

Which MySQL version are you using?
I'm perfectly sure I read that somewhere, thank you for confirming.

I'm using the latest one by BlueG, R39-5. Include and plugin updated. I hade this error before yesterdays update.
Reply
#7

Is it possible we could actually see the MYSQL_Connect part of the script (obviously removing any private data like passwords). Also have you attempted to make a more simple script with just a connection to see if the connection works on that script?
Reply
#8

Quote:
Originally Posted by Septikos
Посмотреть сообщение
Is it possible we could actually see the MYSQL_Connect part of the script (obviously removing any private data like passwords). Also have you attempted to make a more simple script with just a connection to see if the connection works on that script?
pawn Код:
//global variable
new mysql;

OnGameModeInit(){
mysql = mysql_connect(MYSQL_HOST, MYSQL_USER,MYSQL_DATABASE,MYSQL_PASSWORD);
}
I have not tried creating a smaller script since the functions work without error. The "CJ spawning" issue I solved by creating a timer setting the player spawn info since the query could have some slight delay.
Reply
#9

I have spent the last half an hour or so to try and recreate your issue using your code. It doesn't seem to be working.

Quote:

The reason why I believe this is that I call mysql_connect on OnGameModeInit and if so, the includes does not have a valid connection handle hence initialized on the top of my script. I tried putting the includes under OnGameModeInit, but it didn't give any result.

I am pretty sure this isn't true though, have you tried creating a small script that literally is a connection, then a function using information from the mysql and seeing if this works?

If this doesn't have the same issues then, I'm all out of ideas.

Best of luck.
Reply
#10

Quote:
Originally Posted by Septikos
Посмотреть сообщение
I have spent the last half an hour or so to try and recreate your issue using your code. It doesn't seem to be working.



I am pretty sure this isn't true though, have you tried creating a small script that literally is a connection, then a function using information from the mysql and seeing if this works?

If this doesn't have the same issues then, I'm all out of ideas.

Best of luck.
Thank you for trying.

These are some of the includes I have in my gamemode:
Код:
#include <a_mysql>
#include <mysqlsettings> // Here lies the define MYSQL_HOST etc. along with the global variable "mysql".
#include <loginquery> //Here lies the loginquery script in the first post

OnGameModeInit() {
      mysql = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_DATABASE, MYSQL_PASSWORD);
}
I've also tried this inside the mysqlsettings.inc, but no success in removing the errors.
Код:
ConnectMySQL();
forward ConnectMySQL();
public ConnectMySQL()
{
 	mysql = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_DATABASE, MYSQL_PASSWORD);
	return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)