Discussion of article "How to Access the MySQL Database from MQL5 (MQL4)" - page 6

 
elugovoy:

Hello, which version of MT5 terminal you are using?

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 using?

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.

I will try to test it and deliver the solution.

 
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.

I will try to test it and deliver the solution.

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'


Files:
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.

I will try to test it and deliver the solution.

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'


Additional files:

senddata.mq4 11 kb

The sendata.mq4 is my uploaded EA source code.

 
elugovoy:
Can you provide the source code of your EA/Script?
//+------------------------------------------------------------------+
//|& nbsp; Database Operations.mq4 |
//| Copyright 2015, MetaQuotes Software Corp.
//| & nbsp nbsp; 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"; //Server IP, e.g. 192.168.1.210, localhost
input string User = "root"; //mysql database login user name
input string Password = "root"; //Mysql Database Password
input string Database = "test"; //Mysql Database Name
input string Socket = "0"; // database credentials
input int Port = 3306; // mysql database port number
input int ClientFlag = 0; // database credentials

int DB = 0; // database identifier //---
int timeSeconds = 1; // timer
#include <MQLMySQL.mqh

string Query; int i,Cursor,Rector

int i,Cursor,Rows; //Include <MQLMySQL.mqh> string Query.
//+------------------------------------------------------------------+
//| Expert initialisation function & nbsp; |
//+------------------------------------------------------------------+
int OnInit()
OnInit()
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialisation function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{

}
//+------------------------------------------------------------------+
//| Expert tick function & nbsp; |
//+------------------------------------------------------------------+
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); //inst syDB = 0; // database identifier//---
//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); 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客户端内置的交易策略语言。语言允许编写您自己的自动交易系统,技术指标,脚本和函数程序库