文章 "如何从 MQL5 (MQL4) 访问 MySQL 数据库" - 页 6

 
elugovoy:

Hello,

which version of MT5 terminal you are uses?

please try latest update of MQLMySQL libraries, attached here.

I have used the latest version of MT4, when only use one call, it's OK, But when use Sender send data and use receiver reccive data at the same MT4 at the same time, the MT4 print the error "Access violation read to 0x65D6954".
 
elugovoy:

Hello,

which version of MT5 terminal you are uses?

please try latest update of MQLMySQL libraries, attached here.

   I s  the mqlmysql.dll is 
singleton call, the same mt4 can't multicall this dll 
 

Maybe you have libmysql.dll in different locations in your operating system.

if you have libmysql.dll in %WINDOWS%\SYSTEM32 folder, you have to delete it from MT4\MQL4\Experts\Libraries

so the only one dll have to be used.

The one terminal attaches the library once, even if expert advisor used for different charts. so, the reason is different.

The MQLMySQL.dll uses mutexes for accessing internal shared data, so it's also can't be a reason.

If you can, please provide me with the MQL code you are uses to raise such situation and the build number of MT4, I will try to test it and deliver the solution.

 

Thanks. 

 
elugovoy:

Maybe you have libmysql.dll in different locations in your operating system.

if you have libmysql.dll in %WINDOWS%\SYSTEM32 folder, you have to delete it from MT4\MQL4\Experts\Libraries

so the only one dll have to be used.

The one terminal attaches the library once, even if expert advisor used for different charts. so, the reason is different.

The MQLMySQL.dll uses mutexes for accessing internal shared data, so it's also can't be a reason.

If you can, please provide me with the MQL code you are uses to raise such situation and the build number of MT4, I will try to test it and deliver the solution.

 

Thanks. 

MQL CODE is collect mt4 data to the mysql table,  when use in one mt4 in only one, it is ok, when use four or more in two mt4, it print Access violation read to 0x00000002 in ..\MQLMySQL.dll'

 


附加的文件:
sendData.mq4  11 kb
 
elugovoy:

Maybe you have libmysql.dll in different locations in your operating system.

if you have libmysql.dll in %WINDOWS%\SYSTEM32 folder, you have to delete it from MT4\MQL4\Experts\Libraries

so the only one dll have to be used.

The one terminal attaches the library once, even if expert advisor used for different charts. so, the reason is different.

The MQLMySQL.dll uses mutexes for accessing internal shared data, so it's also can't be a reason.

If you can, please provide me with the MQL code you are uses to raise such situation and the build number of MT4, I will try to test it and deliver the solution.

 

Thanks. 

 I used mysql memory table, is it the problem? ENGINE=MEMORY
 
yukaixie:
 I used mysql memory table, is it the problem? ENGINE=MEMORY
I changed the table type engine from memory to Innodb, the problem is still exist. 2015.04.08 15:31:59.296 Access violation read to 0x00000004 in '..MQLMySQL.dll'

 
yukaixie:

MQL CODE is collect mt4 data to the mysql table,  when use in one mt4 in only one, it is ok, when use four or more in two mt4, it print Access violation read to 0x00000002 in ..\MQLMySQL.dll'

 


MySqlDisconnect(DB);

the database disconnection needed, but it's still not solve the problem. 

 
Can you provide the source code of your EA/Script?
 
elugovoy:
Can you provide the source code of your EA/Script?

MQL CODE is collect mt4 data to the mysql table,  when use in one mt4 in only one, it is ok, when use four or more in two mt4, it print Access violation read to 0x00000002 in ..\MQLMySQL.dll'

 


附加的文件:

senddata.mq4 11 kb

the sendata.mq4 is my uploaded EA source code. 

 
elugovoy:
Can you provide the source code of your EA/Script?
//+------------------------------------------------------------------+
//|                                                        数据库操作.mq4 |
//|                        Copyright 2015, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2015, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict


input string Host = "localhost"; //喊单服务器IP,如192.168.1.210, localhost
input string User = "root";  //mysql数据库登录用户名
input string Password = "root"; //mysql数据库登录密码
input string Database = "test";  //mysql数据库名
input string Socket = "0"; // database credentials
input int Port = 3306; //mysql数据库端口号
input int ClientFlag = 0;

int DB = 0; // database identifier//---
int timeSeconds = 1; //定时器
#include <MQLMySQL.mqh>

string Query;

int i,Cursor,Rows;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
{
    
   return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
 {

 }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
{
      
       if( IsExpertEnabled() && IsConnected() && AccountNumber() > 0 )
       {
           
           int account = AccountNumber();
                                
           string symbol = Symbol();     
           
           //int syDB = 0; // database identifier//---
           
           DB = cMySqlConnect(Host, User, Password, Database, Port, Socket, ClientFlag); 
                
           //Alert(DB);
           
           double spread = (Ask - Bid); 
           
           //Alert(symbol);
           
           Query = "SELECT * FROM " + symbol + " where AccountNumber = " + (string)AccountNumber();
           //Print(Query);
           Cursor = MySqlCursorOpen(DB, Query);
             
           
           if (Cursor >= 0)
           {
                 Rows = MySqlCursorRows(Cursor);
                 
                 int dataRows = Rows; 
                 //Alert(dataRows);
                 
                 if( dataRows > 0 )
                 {
                       Query = "update " + symbol + " set Bid = "+(string)Bid + ", Ask = " + (string)Ask
                       + ", Spread = " + DoubleToStr(spread, Digits)  
                       + ", Time = '" + TimeToString(TimeLocal(), TIME_DATE|TIME_SECONDS) +"' where AccountNumber = " 
                       + (string)account; // + "' and Symbol = '" + symbol +"'";
                       
                       MySqlExecute(DB, Query);
                        
                 }
                 else if( dataRows == 0 )
                 {
                      
                      Query = "CREATE TABLE IF NOT EXISTS " + symbol + " (id int NOT NULL AUTO_INCREMENT PRIMARY KEY, AccountNumber int, "
                      + "Symbol char(20), Bid double, Ask double, Spread double," 
                      + "Memo char(50), " 
                      + "Time datetime)ENGINE=MEMORY DEFAULT CHARSET=utf8 "; 
                      
                      MySqlExecute(DB, Query);
                      
                      Query = "INSERT INTO " + symbol + "(AccountNumber, Symbol, Bid, Ask, Spread, Memo, Time) VALUES (" 
                      + (string)account + ", '" + symbol + "', "+(string)Bid+","+ (string)Ask + "," 
                      + DoubleToStr(spread, Digits) 
                      + ", '" + (string)AccountCompany()
                      +"', \'"+TimeToString(TimeLocal(), TIME_DATE|TIME_SECONDS)+"\')";
                      
                      if(MySqlExecute(DB, Query) != true )
                      {
                           //Query = "DROP TABLE IF EXISTS `data_table`";
                           //MySqlExecute(DB, Query);
                           Query = "CREATE TABLE IF NOT EXISTS " + symbol + "(id int NOT NULL AUTO_INCREMENT PRIMARY KEY, AccountNumber int, "
                            + "Symbol char(20), Bid double, Ask double, Spread double," 
                            + "Memo char(50), " 
                            + "Time datetime)ENGINE=MEMORY DEFAULT CHARSET=utf8 "; 
                            
                           MySqlExecute(DB, Query);
                      }
                     
                 }                
                 
                 MySqlCursorClose(Cursor); // NEVER FORGET TO CLOSE CURSOR !!!
            }
            
        }
      
}
//+------------------------------------------------------------------+

 

I used three DB connect, but I used the same DB, is it need to create new  DB for any new database CRUD?


自动交易和策略测试
自动交易和策略测试
  • www.mql5.com
MQL5:MetaTrader 5客户端内置的交易策略语言。语言允许编写您自己的自动交易系统,技术指标,脚本和函数程序库