Access violation libmysql.dll

 

Hello all:

Ive been using mysql for working with my EAs for some time now, I used mainly this EAX Library https://www.mql5.com/en/code/855, which I added a couple of functions and some error handlers for reconnections in case the connection gets dropped while executing a query, everything works perfectly except for one scenario when I load a lot of experts (9 at this point) on a single terminal all using this type of connection, when I restart my computer and load the terminal I would often get Access violation at 0x000000007788E4E4 write to 0x0000000000000024 and that expert will freeze there, If i close the terminal and open it back again without restarting the computer it will load without any problems, after a long research and debugging on my EAs Ive found out that this access violation will happen when the EA is trying to allocate the memory for the mysql object using the function mysql_init(), I was wondering if anyone can shed some light over here, if theres a way for me to ignore the exception and let the expert continue or if theres a workaround. Here is a little resumed code that will cause the error, am working on Windows 7 Ultimate x6, MySQL DataBase 5.1.73, libmysql 6.1.2.


#include <EAX\EAX_Mysql.mqh>

input string MYSQLSTR="++++ MYSQL CONNECTION PARAMETERS ++++";
input string MySqlHost="localhost"; //MySql Host:
input string MySqlUser="user";     //MySQL User:
input string MySqlPass="1234";      //MySQL Password:
input string MySqlDB="sqltest";     //MySQL Table:
input int    MySqlPort=3306;        //MySQL Port:

//--- FUNCION DE INICIALIZACION
int OnInit()
  {
   return(0);
  }
//--- FUNCION DE DESINICIALIZACION
void OnDeinit(const int reason)
  {
//--- MODULO DE SENALES
  }
//--- FUNCION DE EJECUCION POR TICKS
void OnTick()
  {
   Sleep(5000);
   Print("GetTimeFrame 1");
   EAX_Mysql *db=new EAX_Mysql();
   db.connect(MySqlHost,MySqlUser,MySqlPass,MySqlDB);
   string query="";
   StringConcatenate(query,"SELECT CF_UpdateNumber FROM config WHERE CF_Key = '0'","");
   int iResults=db.read_rows(query);
   string portfolioidrs=0;
   for(int i=0; i<iResults; i++)
     {
      portfolioidrs=(string) db.get("CF_UpdateNumber",i);
     }
   delete db;
   Print("GetTimeFrame = ", portfolioidrs);
  }
EAX_Mysql - MySQL library
EAX_Mysql - MySQL library
  • votes: 21
  • 2012.08.22
  • Michael Schoen
  • www.mql5.com
This library allows an easy interface to MySQL.
 
midnightwalker0:

Hello all:

Ive been using mysql for working with my EAs for some time now, I used mainly this EAX Library https://www.mql5.com/en/code/855, which I added a couple of functions and some error handlers for reconnections in case the connection gets dropped while executing a query, everything works perfectly except for one scenario when I load a lot of experts (9 at this point) on a single terminal all using this type of connection, when I restart my computer and load the terminal I would often get Access violation at 0x000000007788E4E4 write to 0x0000000000000024 and that expert will freeze there, If i close the terminal and open it back again without restarting the computer it will load without any problems, after a long research and debugging on my EAs Ive found out that this access violation will happen when the EA is trying to allocate the memory for the mysql object using the function mysql_init(), I was wondering if anyone can shed some light over here, if theres a way for me to ignore the exception and let the expert continue or if theres a workaround. Here is a little resumed code that will cause the error, am working on Windows 7 Ultimate x6, MySQL DataBase 5.1.73, libmysql 6.1.2.


Sounds as if you know what the problem is but don't know where to start..

Ive found out that this access violation will happen when the EA is trying to allocate the memory for the mysql object using the function mysql_init()

 
wehsnim:

Sounds as if you know what the problem is but don't know where to start..

Ive found out that this access violation will happen when the EA is trying to allocate the memory for the mysql object using the function mysql_init()

I know that the error is happening specifically on that line, since am using the MySQL C API, I dont belive the error is being caused because of a bad DLL but by some kind of memory management done by MT5 when its loading its resources, I know this is a very specific error, but maybe someone in Metaquotes can give me a hint if its my code or if there is something I can do to fix it.
 
midnightwalker0:
I know that the error is happening specifically on that line, since am using the MySQL C API, I dont belive the error is being caused because of a bad DLL but by some kind of memory management done by MT5 when its loading its resources, I know this is a very specific error, but maybe someone in Metaquotes can give me a hint if its my code or if there is something I can do to fix it.
Have you logged this with service desk to see if they can help?  You might get a quicker reply.
 

@midnightwalker0:

Have you solved this issue? I am also experiencing issues with memory allocation. I'm also using windows 7 though I have the most recent .dd release (6.1.5.0)

 
fxuser1769:

@midnightwalker0:

Have you solved this issue? I am also experiencing issues with memory allocation. I'm also using windows 7 though I have the most recent .dd release (6.1.5.0)

Are your also having this issue only when MT5 starts?
 
hey i've been experiencing this issue myself, once mt5 is loaded it works just fine but am getting some weird memory errors they look like memory addresses to me but am no expert programer, were you able to find a solution? please share thanks!
 
rscatuso:
hey i've been experiencing this issue myself, once mt5 is loaded it works just fine but am getting some weird memory errors they look like memory addresses to me but am no expert programer, were you able to find a solution? please share thanks!
Hey there, Its pretty much whats been happening to me, good to know am not the only one experiencing this!, Ive already submited a ticket with Service Desk hopefully ill get some kind of answer.
 

I've been having those Access Violation errors too, and I figured out how to fix them.

It happens that in many places, the type int is used to hold the value of what is actually a pointer to some structure or object belonging to the MySQL lib and that is not interpreted by MQL5, so you just store it as int for reference. However, the type int is 32-bits regardless of your architecture, and if you are using 64-bit system, the type int is not big enough to contain the value of a pointer. You have to use long instead.

Most libmysql.dll functions return pointers, such as mysql_init(), mysql_real_connect(), mysql_real_query(), etc, and most MQL5 scripts store the return value of those functions as int, an insufficient data type to represent those pointers, which is causing those problems.

I managed to get my scripts working perfectly in 64-bit environment by using long instead of int in some strategic places. Since all I really need is to insert stuff in the database, I only needed to change the functions I mentioned above.

 
Nick Rios:
Hey there, Its pretty much whats been happening to me, good to know am not the only one experiencing this!, Ive already submited a ticket with Service Desk hopefully ill get some kind of answer.
When you get a response back from them, and/or figure out how to solve this problem through other means, please be kind and share that info back here, in case people later on get stuck with a similar problem.
 
Havenard:

I've been having those Access Violation errors too, and I figured out how to fix them.

It happens that in many places, the type int is used to hold the value of what is actually a pointer to some structure or object belonging to the MySQL lib and that is not interpreted by MQL5, so you just store it as int for reference. However, the type int is 32-bits regardless of your architecture, and if you are using 64-bit system, the type int is not big enough to contain the value of a pointer. You have to use long instead.

Most libmysql.dll functions return pointers, such as mysql_init(), mysql_real_connect(), mysql_real_query(), etc, and most MQL5 scripts store the return value of those functions as int, an insufficient data type to represent those pointers, which is causing those problems.

I managed to get my scripts working perfectly in 64-bit environment by using long instead of int in some strategic places. Since all I really need is to insert stuff in the database, I only needed to change the functions I mentioned above.

Wow. Thank you for a great reply and explanation! Your answer was kind of hard to find and notice but it was an only working solution on windows 10 64 bit + mt5 64 bit.
Reason: