Permalink
Browse files

Attempt to add an error string which Windows provides after a failed …

…call to LoadLibrary. See http://www.heidisql.com/forum.php?t=22514
  • Loading branch information...
ansgarbecker committed Jan 23, 2017
1 parent 53b4ab6 commit b6e1f8012ee97f3614cd981975427c1c7a718a22
Showing with 15 additions and 5 deletions.
  1. +15 −5 source/dbconnection.pas
View
@@ -2073,13 +2073,19 @@ procedure TDBConnection.DoBeforeConnect;
procedure TMySQLConnection.DoBeforeConnect;
var
msg: String;
begin
// Init libmysql before actually connecting.
if LibMysqlHandle = 0 then begin
Log(lcDebug, f_('Loading library file %s ...', [LibMysqlPath]));
LibMysqlHandle := LoadLibrary(PWideChar(LibMysqlPath));
if LibMysqlHandle = 0 then
raise EDatabaseError.CreateFmt(_('Cannot find a usable %s. Please launch %s from the directory where you have installed it.'), [LibMysqlPath, ExtractFileName(ParamStr(0))])
if LibMysqlHandle = 0 then begin
msg := f_('Cannot find a usable %s. Please launch %s from the directory where you have installed it.', [LibMysqlPath, ExtractFileName(ParamStr(0))]);
if Windows.GetLastError <> 0 then
msg := msg + CRLF + CRLF + f_('Internal error %d:', [Windows.GetLastError]) + ' ' + SysErrorMessage(Windows.GetLastError);
raise EDatabaseError.Create(msg);
end
else begin
AssignProc(@mysql_affected_rows, 'mysql_affected_rows');
AssignProc(@mysql_character_set_name, 'mysql_character_set_name');
@@ -2118,7 +2124,7 @@ procedure TMySQLConnection.DoBeforeConnect;
procedure TPgConnection.DoBeforeConnect;
var
LibWithPath: String;
LibWithPath, msg: String;
begin
// Init lib before actually connecting.
// Each connection has its own library handle
@@ -2131,8 +2137,12 @@ procedure TPgConnection.DoBeforeConnect;
Log(lcInfo, f_('Trying to load library with full path: %s', [LibWithPath]));
LibPqHandle := LoadLibrary(PWideChar(LibWithPath));
end;
if LibPqHandle = 0 then
raise EDatabaseError.CreateFmt(_('Cannot find a usable %s. Please launch %s from the directory where you have installed it.'), [LibPqPath, ExtractFileName(ParamStr(0))])
if LibPqHandle = 0 then begin
msg := f_('Cannot find a usable %s. Please launch %s from the directory where you have installed it.', [LibPqPath, ExtractFileName(ParamStr(0))]);
if Windows.GetLastError <> 0 then
msg := msg + CRLF + CRLF + f_('Internal error %d:', [Windows.GetLastError]) + ' ' + SysErrorMessage(Windows.GetLastError);
raise EDatabaseError.Create(msg);
end
else begin
AssignProc(@PQconnectdb, 'PQconnectdb');
AssignProc(@PQerrorMessage, 'PQerrorMessage');

0 comments on commit b6e1f80

Please sign in to comment.