Skip to content

Commit b6e1f80

Browse files
committed
Attempt to add an error string which Windows provides after a failed call to LoadLibrary. See http://www.heidisql.com/forum.php?t=22514
1 parent 53b4ab6 commit b6e1f80

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

source/dbconnection.pas

+15-5
Original file line numberDiff line numberDiff line change
@@ -2073,13 +2073,19 @@ procedure TDBConnection.DoBeforeConnect;
20732073

20742074

20752075
procedure TMySQLConnection.DoBeforeConnect;
2076+
var
2077+
msg: String;
20762078
begin
20772079
// Init libmysql before actually connecting.
20782080
if LibMysqlHandle = 0 then begin
20792081
Log(lcDebug, f_('Loading library file %s ...', [LibMysqlPath]));
20802082
LibMysqlHandle := LoadLibrary(PWideChar(LibMysqlPath));
2081-
if LibMysqlHandle = 0 then
2082-
raise EDatabaseError.CreateFmt(_('Cannot find a usable %s. Please launch %s from the directory where you have installed it.'), [LibMysqlPath, ExtractFileName(ParamStr(0))])
2083+
if LibMysqlHandle = 0 then begin
2084+
msg := f_('Cannot find a usable %s. Please launch %s from the directory where you have installed it.', [LibMysqlPath, ExtractFileName(ParamStr(0))]);
2085+
if Windows.GetLastError <> 0 then
2086+
msg := msg + CRLF + CRLF + f_('Internal error %d:', [Windows.GetLastError]) + ' ' + SysErrorMessage(Windows.GetLastError);
2087+
raise EDatabaseError.Create(msg);
2088+
end
20832089
else begin
20842090
AssignProc(@mysql_affected_rows, 'mysql_affected_rows');
20852091
AssignProc(@mysql_character_set_name, 'mysql_character_set_name');
@@ -2118,7 +2124,7 @@ procedure TMySQLConnection.DoBeforeConnect;
21182124

21192125
procedure TPgConnection.DoBeforeConnect;
21202126
var
2121-
LibWithPath: String;
2127+
LibWithPath, msg: String;
21222128
begin
21232129
// Init lib before actually connecting.
21242130
// Each connection has its own library handle
@@ -2131,8 +2137,12 @@ procedure TPgConnection.DoBeforeConnect;
21312137
Log(lcInfo, f_('Trying to load library with full path: %s', [LibWithPath]));
21322138
LibPqHandle := LoadLibrary(PWideChar(LibWithPath));
21332139
end;
2134-
if LibPqHandle = 0 then
2135-
raise EDatabaseError.CreateFmt(_('Cannot find a usable %s. Please launch %s from the directory where you have installed it.'), [LibPqPath, ExtractFileName(ParamStr(0))])
2140+
if LibPqHandle = 0 then begin
2141+
msg := f_('Cannot find a usable %s. Please launch %s from the directory where you have installed it.', [LibPqPath, ExtractFileName(ParamStr(0))]);
2142+
if Windows.GetLastError <> 0 then
2143+
msg := msg + CRLF + CRLF + f_('Internal error %d:', [Windows.GetLastError]) + ' ' + SysErrorMessage(Windows.GetLastError);
2144+
raise EDatabaseError.Create(msg);
2145+
end
21362146
else begin
21372147
AssignProc(@PQconnectdb, 'PQconnectdb');
21382148
AssignProc(@PQerrorMessage, 'PQerrorMessage');

0 commit comments

Comments
 (0)