error 126

 

2010.07.01 15:33:22 mysql_v2.2 AUDJPYFXF,H1: cannot load library 'C:\MT4\experts\libraries\mysql_wrapper.dll' (error 126)

I keep getting this error when I try to place this EA on a chart. The dll is in the folder it's supposed to be and I'm running this EA on my home PC. Completely lost here.

//+------------------------------------------------------------------+
//|                                                        mysql.mqh |
//|                                Copyright © 2008, Berkers Trading |
//|                                                http://quotar.com |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, Berkers Trading"
#property link      "http://quotar.com"

#import "C:\MT4\experts\libraries\mysql_wrapper.dll"
string   MT4_mysql_wrapper_version    ();
int      mysql_init        (int db);
int      mysql_errno       (int MySQL);
string   mysql_error       (int MySQL);
int      mysql_real_connect(int MySQL, string host, string user, string password, string DB, int port, int socket, int clientflag);
int      mysql_real_query  (int MySQL, string query, int length);
int      mysql_query       (int MySQL, string query);
void     mysql_close       (int MySQL);

int      mysql_store_result(int MySQL);
int      mysql_use_result  (int MySQL);
string   mysql_fetch_row   (int result);
void     MT4_mysql_fetch_row   (int result, string& row[]);
void     MT4_mysql_fetch_fields_string  (int result, string& row[], int type);
int      mysql_num_fields  (int result);
string   mysql_fetch_field (int result);
int      mysql_num_rows    (int result);
void     mysql_free_result (int result);
int      mysql_insert_id   (int MySQL);
#import

#define MYSQL_VERBOSE 1

#define FIELD_NAME      0
#define FIELD_ORGNAME   1
#define FIELD_TABLE     2
#define FIELD_ORGTABLE  3
#define FIELD_DB        4
#define FIELD_CATALOG   5
#define FIELD_DEF       6

extern string MYSQL     = "********************";
extern string Host      = "localhost";
extern string User      = "mql";
extern string Password  = "apenstaart";
extern string Database  = "forex";
extern int    Port      = 3306;

int  giMySQL;
bool gbMySQLInitialized = FALSE;

int MySQL_Init() {
   
   giMySQL = mysql_init(giMySQL);
   if(giMySQL != 0 && MYSQL_VERBOSE > 0){ 
       Print("MySQL allocated");
   }
   int liConnect = mysql_real_connect(giMySQL, Host, User, Password, Database, Port, NULL, 0);
   if (liConnect == giMySQL){ 
       if(MYSQL_VERBOSE > 0){
         Print("MySQL connected");
       }
       gbMySQLInitialized = TRUE;
   } else {
       MySQL_NoError();
   }   
   return(0);
}

int MySQL_DeInit(){
   
   mysql_close(giMySQL);
   return(0);
}

bool MySQL_NoError(){
   
   int liError = mysql_errno(giMySQL);
   if (liError > 0){
      if(MYSQL_VERBOSE > 0) Print("MySQL error=", liError, " ", mysql_error(giMySQL)); 
      return(FALSE);
   }
   return(TRUE);
}

bool MySQL_FetchRow(string sQuery, string &sResultSet[]){
   
   int i;
   if (gbMySQLInitialized == FALSE) return(FALSE);   
   if (MYSQL_VERBOSE > 1) Print(sQuery);
   
   int liLength= StringLen(sQuery);    
   mysql_real_query(giMySQL, sQuery, liLength);   
   
   int liResult = mysql_store_result(giMySQL);
   ArrayResize(sResultSet, mysql_num_fields(liResult));
   MT4_mysql_fetch_row(liResult, sResultSet);  
  
   //for (i = 0; i < ArrayRange(sResultSet,0); i++){
   //     Print(i+"="+sResultSet[i]);
   //}
   mysql_free_result(liResult);
   return(MySQL_NoError());
}

bool MySQL_FetchArray(string sQuery, string &sResultSet[][]){
   
   int i,j;
   if (gbMySQLInitialized == FALSE) return(FALSE);   
   if (MYSQL_VERBOSE > 1) Print(sQuery);
   
   int liLength= StringLen(sQuery);    
   mysql_real_query(giMySQL, sQuery, liLength);   
   
   int liResult = mysql_store_result(giMySQL);
   string lsResult[0];
   int liNumRow   = mysql_num_rows(liResult);
   int liNumField = mysql_num_fields(liResult);
   
   ArrayResize(lsResult, liNumField);
   ArrayResize(sResultSet, liNumRow);
  // string sFieldSet[7];
  // ArrayResize(sFieldSet, mysql_num_fields(iResult));
  // MT4_mysql_fetch_fields_string(iResult, sFieldSet,FIELD_NAME);
   
   for (i = 0; i < liNumRow; i++){
      MT4_mysql_fetch_row(liResult, lsResult);  
      for (j = 0; j < liNumField; j++){
           sResultSet[i][j] = lsResult[j];
           //Print(i+","+j+":="+sResultSet[i][j]);
      }
   }
   mysql_free_result(liResult);
   return(MySQL_NoError());
}


int start()
{
MySQL_Init();
}
 

I

Dont believe you need the path, just the filename (with extension) - if its in the <right> libraries folder :)

Good Luck

-BB-

 
BarrowBoy:

Dont believe you need the path, just the filename (with extension) - if its in the <right> libraries folder :)

If it's definitely in the right folder then it could be a problem of missing dependencies. I've just had a quick look at what appears to be the source of this file - https://www.mql5.com/en/forum/111508 - and mysql_wrapper.dll is dependent on libmysql.dll. I know more or less nothing about MySQL, but if the libmysql.dll file is missing, or isn't present somewhere on the system path, then mysql_wrapper.dll will fail to load.
 

Both libmysql.dll and mysql_wrapper.dll are in the same folder as the EA, the Experts folder. Not in Experts/Libraries/.

Should I move them there? Aslo I notice there is no #import libmysql.dll in the EA, but you say it is needed to load the EA properly, should I add an import for it in the EA code?

Would the fact that I installed MT4 on my C drive folder instead of in the standard Programs folder have anythingt o do with this error?

It really makes no sense to me. JJC is right, this code was written by somebody else and the link he put up is the right one. I would have to assume that the author and the other posters in that thread got this to work somehow....?

 
inkexit:

Both libmysql.dll and mysql_wrapper.dll are in the same folder as the EA, the Experts folder. Not in Experts/Libraries/.

mysql_wrapper.dll should definitely be in either the experts\libraries directory or somewhere on the system path. Putting it in the same directory as the EA will not work. That, quite simply, is almost certainly your problem, as BB had already guessed.

I know nothing about MySQL (see above), but libmysql.dll should either be in the same directory as mysql_wrapper.dll or, preferably, somewhere on the system path.

("System path" can basically be taken to mean the system directory. On 32-bit versions of Windows, this is usually \Windows\System32. On 64-bit versions of Windows the correct directory in this context is usually \Windows\SysWOW64, not \Windows\System32, for reasons which I'm not going to go into here.)

inkexit:

Aslo I notice there is no #import libmysql.dll in the EA, but you say it is needed to load the EA properly, should I add an import for it in the EA code?

No, you don't need to do that: libmysql.dll is loaded implicitly by mysql_wrapper.dll and using #import on it will make no difference. mysql_wrapper.dll will fail to load if it (or, strictly speaking, the operating system) is unable to find libmysql.dll. Nothing you do within your EA will affect this.

 

IDK, this is mind bogling. I placed mysql_wrapper.dll in windows\system32. Now I get the same error message, except for the error code number, instead of 126, now i get error 127.

This is driving me crazy.!!!!!!!! <PULLS OUT HAIR>

 

I put together a zipfile of the source files and library files below. I left my real SQL login info in the mqh file so everybody else can check to see if they can get this to work, I can easily change them later. Dont fill the database up with toooo much garbage lol!

Also, here's the c++ file for mysql_wrapper. Other than mysql.h, which came in the original authors zip file, it looks like it includes a number of files that I have no idea what they are or where i can find them:

#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
#include "mysql.h"

maybe these files have to be in the libraries folder?

//+------------------------------------------------------------------+
//|                                                mysql_wrapper.c++ |
//|                                Copyright © 2008, Berkers Trading |
//|                                                http://quotar.com |
//+------------------------------------------------------------------+
#include "stdafx.h"

#define WIN32_LEAN_AND_MEAN  // Exclude rarely-used stuff from Windows headers
#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
#include "mysql.h"

//----
#define MT4_EXPFUNC __declspec(dllexport)

struct MqlStr{
   int               len;
   char             *string;
};
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
BOOL APIENTRY DllMain(HANDLE hModule,DWORD ul_reason_for_call,LPVOID lpReserved)
  {
//----
   switch(ul_reason_for_call)
     {
      case DLL_PROCESS_ATTACH:
      case DLL_THREAD_ATTACH:
      case DLL_THREAD_DETACH:
      case DLL_PROCESS_DETACH:
         break;
     }
//----
   return(TRUE);
  }

MT4_EXPFUNC char* __stdcall MT4_mysql_wrapper_version(){

        return("mysql_wrapper v1.0.1 Copyright © 2008, Berkers Trading");
}

MT4_EXPFUNC void __stdcall MT4_mysql_fetch_row(MYSQL_RES* res, MqlStr *row){
        //char buffer [50];
        //sprintf (buffer, "%d ", sizeof(MqlStr));
        //MessageBox(NULL,buffer,"Application Message", MB_OK | MB_ICONINFORMATION);
        
        MYSQL_ROW lrow = mysql_fetch_row(res);

        for (unsigned int i=0; i < mysql_num_fields(res);i++){
                row[i].string = lrow[i];
        }
}
/*
my_ulonglong STDCALL mysql_num_rows(MYSQL_RES *res);
unsigned int STDCALL mysql_num_fields(MYSQL_RES *res);
my_bool STDCALL mysql_eof(MYSQL_RES *res);
MYSQL_FIELD *STDCALL mysql_fetch_field_direct(MYSQL_RES *res,
                                              unsigned int fieldnr);
*/
MT4_EXPFUNC void __stdcall MT4_mysql_fetch_fields_string(MYSQL_RES* res, MqlStr *row, int type){

        MYSQL_FIELD *lrow = mysql_fetch_fields(res);

        for (unsigned int i=0; i < mysql_num_fields(res);i++){
                //MessageBox(NULL,lrow[i].name,"Application Message", MB_OK | MB_ICONINFORMATION);
                switch (type){
                        case 0:
                                row[i].string = lrow[i].name;                           /* Name of column */
                                break;
                        case 1:
                                row[i].string = lrow[i].org_name;           /* Original column name, if an alias */
                                break;
                        case 2:
                                row[i].string = lrow[i].table;              /* Table of column if column was a field */
                                break;
                        case 3:
                                row[i].string = lrow[i].org_table;          /* Org table name, if table was an alias */
                                break;
                        case 4:
                                row[i].string = lrow[i].db;                 /* Database for table */
                                break;
                        case 5:
                                row[i].string = lrow[i].catalog;                        /* Catalog for table */
                                break;
                        case 6:
                                row[i].string = lrow[i].def;                            /* Default value (set by mysql_list_fields) */
                                break;
                }
        }

}

/*
MYSQL_ROW_OFFSET STDCALL mysql_row_tell(MYSQL_RES *res);
MYSQL_FIELD_OFFSET STDCALL mysql_field_tell(MYSQL_RES *res);

unsigned int STDCALL mysql_field_count(MYSQL *mysql);
my_ulonglong STDCALL mysql_affected_rows(MYSQL *mysql);
my_ulonglong STDCALL mysql_insert_id(MYSQL *mysql);
unsigned int STDCALL mysql_errno(MYSQL *mysql);
const char * STDCALL mysql_error(MYSQL *mysql);
const char *STDCALL mysql_sqlstate(MYSQL *mysql);
unsigned int STDCALL mysql_warning_count(MYSQL *mysql);
const char * STDCALL mysql_info(MYSQL *mysql);
unsigned long STDCALL mysql_thread_id(MYSQL *mysql);
const char * STDCALL mysql_character_set_name(MYSQL *mysql);
int          STDCALL mysql_set_character_set(MYSQL *mysql, const char *csname);*//*

MT4_EXPFUNC MYSQL* __stdcall _mysql_init(void){
        MYSQL *mysql_res = mysql_init(0);
        return(mysql_res);
}


my_bool         STDCALL mysql_ssl_set(MYSQL *mysql, const char *key,
                                      const char *cert, const char *ca,
                                      const char *capath, const char *cipher);
const char *    STDCALL mysql_get_ssl_cipher(MYSQL *mysql);
my_bool         STDCALL mysql_change_user(MYSQL *mysql, const char *user, 
                                          const char *passwd, const char *db); 
*//*
MYSQL *         STDCALL mysql_real_connect(MYSQL *mysql, const char *host,
                                           const char *user,
                                           const char *passwd,
                                           const char *db,
                                           unsigned int port,
                                           const char *unix_socket,
                                           unsigned long clientflag);

int             STDCALL mysql_select_db(MYSQL *mysql, const char *db);
int             STDCALL mysql_query(MYSQL *mysql, const char *q);
int             STDCALL mysql_send_query(MYSQL *mysql, const char *q,
                                         unsigned long length);
int             STDCALL mysql_real_query(MYSQL *mysql, const char *q,
                                        unsigned long length);
MYSQL_RES *     STDCALL mysql_store_result(MYSQL *mysql);
MYSQL_RES *     STDCALL mysql_use_result(MYSQL *mysql);
*/
Files:
mysql_v2.2.zip  251 kb
 

Also, here's the original authors zipfile, full of .cnf, .plg, .dsw, .ilf files and a bunch of other stuff that I have no idea what they do. In other words, hopefully, everything we need should be here, except the libmysql.dll file, which is in my zipfile in the post above this one.

Files:
mysql_wrapper.zip  1094 kb
 

bump

 
Hi. Do you have mysql_wrapper for MT 5?
 

inkexit:

maybe these files have to be in the libraries folder?

No. These are C source code (header) files that were included when the DLL was compiled. When you have the compiled DLL the C source does not matter anymore at this point. Its all inside the dll now.


Put the wrapper dll into the experts/libraries folder as you have been instructed already (but refused to do) and remove the full path from your #import statement. It must read #import "mysql_wapper.dll" and nothing else. And if you have properly installed MySQL (the correct version!) on your PC then you should already have libmysql.dll in the correct place.


Do not deviate from the instructions for no reason and then ask why it is not working.

Reason: