Skip to content

Commit 4645c38

Browse files
committed
Load libpq.dll after just checking if it exists. Do not check what LoadLibrary returns. This is quite risky, but there seem to be cases where LoadLibrary returns 0 although libpq.dll was loaded. See http://www.heidisql.com/forum.php?t=21039
1 parent cd35370 commit 4645c38

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

source/dbconnection.pas

+4-4
Original file line numberDiff line numberDiff line change
@@ -2097,11 +2097,11 @@ procedure TPgConnection.DoBeforeConnect;
20972097
// Each connection has its own library handle
20982098
if LibPqHandle = 0 then begin
20992099
LibWithPath := ExtractFileDir(Application.ExeName) + '\' + LibPqPath;
2100-
Log(lcDebug, f_('Loading library file %s ...', [LibWithPath]));
2101-
LibPqHandle := LoadLibrary(PWideChar(LibWithPath));
2102-
if LibPqHandle = 0 then
2103-
raise EDatabaseError.CreateFmt(_('Cannot find a usable %s. Please launch %s from the directory where you have installed it.%s'), [LibPqPath, ExtractFileName(ParamStr(0)), CRLF+CRLF+SysErrorMessage(System.GetLastError)])
2100+
if not FileExists(LibWithPath) then
2101+
raise EDatabaseError.CreateFmt(_('Cannot find a usable %s. Please launch %s from the directory where you have installed it.'), [LibPqPath, ExtractFileName(ParamStr(0))])
21042102
else begin
2103+
Log(lcDebug, f_('Loading library file %s ...', [LibWithPath]));
2104+
LibPqHandle := LoadLibrary(PWideChar(LibWithPath));
21052105
AssignProc(@PQconnectdb, 'PQconnectdb');
21062106
AssignProc(@PQerrorMessage, 'PQerrorMessage');
21072107
AssignProc(@PQresultErrorMessage, 'PQresultErrorMessage');

0 commit comments

Comments
 (0)