From 7fd551bd72ed917dffe351609e5c4c45daeefb77 Mon Sep 17 00:00:00 2001 From: Ansgar Becker Date: Sun, 28 Jul 2019 08:57:51 +0200 Subject: [PATCH] Give the user a hint to download VC redistributable if PostgreSQL dll fails to assign a procedure. See https://www.heidisql.com/forum.php?t=18580#p34297 --- source/dbconnection.pas | 20 +++++++++++++++++--- source/dbstructures.pas | 4 +++- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/source/dbconnection.pas b/source/dbconnection.pas index dd90eb43..633df11d 100644 --- a/source/dbconnection.pas +++ b/source/dbconnection.pas @@ -2231,13 +2231,27 @@ end; procedure TPgConnection.DoBeforeConnect; var - LibraryPath: String; + LibraryPath, + msg: String; begin // Init lib before actually connecting. LibraryPath := ExtractFilePath(ParamStr(0)) + Parameters.LibraryFile; Log(lcDebug, f_('Loading library file %s ...', [LibraryPath])); - FLib := TPostgreSQLLib.Create(LibraryPath); - Log(lcDebug, FLib.DllFile + ' v' + IntToStr(FLib.PQlibVersion) + ' loaded.'); + try + FLib := TPostgreSQLLib.Create(LibraryPath); + Log(lcDebug, FLib.DllFile + ' v' + IntToStr(FLib.PQlibVersion) + ' loaded.'); + except + on E:EDbError do begin + msg := E.Message; + if E.ErrorCode = TDbLib.LIB_PROC_ERROR then begin + msg := msg + sLineBreak + sLineBreak + + f_('Installing VC redistributable might help: %s', + ['https://support.microsoft.com/en-us/help/3179560/update-for-visual-c-2013-and-visual-c-redistributable-package'] + ); + end; + raise EDbError.Create(msg, E.ErrorCode); + end; + end; inherited; end; diff --git a/source/dbstructures.pas b/source/dbstructures.pas index 862bc180..c5b4b6d1 100644 --- a/source/dbstructures.pas +++ b/source/dbstructures.pas @@ -326,6 +326,8 @@ type // DLL loading TDbLib = class(TObject) + const + LIB_PROC_ERROR: Cardinal = 1000; private FDllFile: String; FHandle: HMODULE; @@ -7716,7 +7718,7 @@ begin ); if Windows.GetLastError <> 0 then msg := msg + CRLF + CRLF + f_('Internal error %d: %s', [Windows.GetLastError, SysErrorMessage(Windows.GetLastError)]); - Raise EDbError.Create(msg); + Raise EDbError.Create(msg, LIB_PROC_ERROR); end; end; end;