Cannot find a usable libpq.dll

[expired user #8985]'s profile image [expired user #8985] posted 9 years ago in Creating a connection Permalink
I'm trying to connect to a PostgreSQL database on a network server.

I've done the following things:
- installed PostgreSQL on my Windows 7 machine
- restarted my machine
- downloaded the latest version of HeidiSQL (9.2.0.4947)
- copied the libpq.dll from C:\Program Files\PostgreSQL\9.4\lib\ to C:\Program Files\HeidiSQL\
- launched HeidiSQL from C:\Program Files\HeidiSQL\

Yet I'm still getting the following error message:
Cannot find a usable libpq.dll. Please launch heidisql.exe from the directory where you have installed it.

How do I get HeidiSQL to connect to a PostgreSQL database on a network server without getting this error?
[expired user #8985]'s profile image [expired user #8985] posted 9 years ago Permalink
Bump...
ansgar's profile image ansgar posted 9 years ago Permalink
Looks like you did not install HeidiSQL properly. That libpq.dll (32/64bit version, depending on your OS) is installed in the right directory when using the HeidiSQL installer. Of course the portable ZIP file also contains a working libpq.dll.

You should not be required to copy some other .dll file to HeidiSQL's folder.
[expired user #8985]'s profile image [expired user #8985] posted 9 years ago Permalink
I uninstalled HeidiSQL via the Control Panel in Windows 7. I verified that C:\Program Files\HeidiSQL\ folder was removed. I then reinstalled using the installer I downloaded from http://www.heidisql.com/installers/HeidiSQL_9.2.0.4947_Setup.exe.

After that, I launched HeidiSQL and got the following window. It still says that PostgreSQL is experimental (see attachment 1). And I still get the same error as shown in attachment 2.

How do I install HeidiSQL so that I can connect to PostgreSQL?
2 attachment(s):
  • heidi1
  • heidi2
[expired user #8985]'s profile image [expired user #8985] posted 9 years ago Permalink
Anyone?
ansgar's profile image ansgar posted 9 years ago Permalink
Probably that libpq.dll is blocked by your antivirus software?
I don't know. You could try on another machine.
[expired user #9593]'s profile image [expired user #9593] posted 9 years ago Permalink

I'm running into this issue on a fresh install of Win10 (worked on the previous win10 upgrade).

ansgar's profile image ansgar posted 9 years ago Permalink

Please look into the folder where you installed HeidiSQL, and watch out if there is a libpq.dll. If no, then the installer did something wrong. But I guess that is some issue with file privileges.

[expired user #9593]'s profile image [expired user #9593] posted 9 years ago Permalink

I looks like if you use the installer on a 64-bit machine it installs the 64bit-version, but libpq.dll is not a 64-bit version. I used the portable zip and was able to get it to run the 32 bit version.

ansgar's profile image ansgar posted 9 years ago Permalink

That would mean PostgreSQL would not work on any 64bit machine. Can't believe that, but I can check that.

Which version of the installer did you use?

[expired user #9593]'s profile image [expired user #9593] posted 9 years ago Permalink

Probably the wrong one =D (HeidiSQL_9.3.0.4984_Setup.exe).

[expired user #9593]'s profile image [expired user #9593] posted 9 years ago Permalink

Well, I just tried the "HeidiSQL_9.3.0.5049_Setup", same issue. However, if I put "heidisql32.r5049.exe" in the folder and run it, it works, but but the 64 bit version. The 32 version crashes on exit though.

date/time          : 2016-02-09, 08:09:50, 887ms
computer name      : DEVELOPER-VS
user name          : Caleb-VS
operating system   : Windows 10 x64 build 10586
system language    : English
system up time     : 6 days
program up time    : 8 seconds
processors         : 8x Intel(R) Core(TM) i7-4720HQ CPU @ 2.60GHz
physical memory    : 5486/16296 MB (free/total)
free disk space    : (C:) 96.10 GB
display mode       : 1536x864, 32 bit
process id         : $2e08
allocated memory   : 43.66 MB
largest free block : 1.12 GB
executable         : heidisql32.r5049.exe
exec. date/time    : 2016-02-09 08:05
version            : 9.3.0.5049
compiled with      : Delphi XE5
madExcept version  : 4.0.12
callstack crc      : $56492c7f, $c70d16f6, $c70d16f6
exception number   : 1
exception class    : EAccessViolation
exception message  : Access violation at address 56492C7F in module 'libpq.dll'. Write of address 001A0010.

main thread ($3f28):
56492c7f libpq.dll
564920ca libpq.dll                                     PQfinish
0083cb06 heidisql32.r5049.exe dbconnection    1960 +47 TPgConnection.SetActive
0094a844 heidisql32.r5049.exe Main            2051 +52 TMainForm.ConnectionsNotify
0040c978 heidisql32.r5049.exe System           196  +0 DynArraySetLength
008616a2 heidisql32.r5049.exe dbconnection      38  +0 {System.Generics.Collections}TList<dbconnection.TDBConnection>.Notify
00862317 heidisql32.r5049.exe dbconnection     728  +0 {System.Generics.Collections}TObjectList<dbconnection.TDBConnection>.Notify
00861eb0 heidisql32.r5049.exe dbconnection     728  +0 {System.Generics.Collections}TList<dbconnection.TDBConnection>.DeleteRange
00861508 heidisql32.r5049.exe dbconnection      38  +0 {System.Generics.Collections}TList<dbconnection.TDBConnection>.SetCount
0067b8a1 heidisql32.r5049.exe Vcl.Forms                TCustomForm.DoDestroy
0067b6f2 heidisql32.r5049.exe Vcl.Forms                TCustomForm.Destroy
004a6a99 heidisql32.r5049.exe madExcept                InterceptClassDestroy
004084b0 heidisql32.r5049.exe System           196  +0 TObject.Free
0053a47f heidisql32.r5049.exe System.Classes           TComponent.DestroyComponents
00679481 heidisql32.r5049.exe Vcl.Forms                DoneApplication
0044c3a1 heidisql32.r5049.exe System.SysUtils          DoExitProc
00409fe9 heidisql32.r5049.exe System           196  +0 @Halt0
00986a8d heidisql32.r5049.exe heidisql          80 +26 initialization
766e38f2 KERNEL32.DLL                                  BaseThreadInitThunk
ansgar's profile image ansgar posted 9 years ago Permalink

Yes, that's a known issue in the 32bit version of heidisql.exe/libpq.dll. So, that's normal for now. The important thing is you have the 32bit version of libpq.dll while you had the 64bit version of heidisql.exe before, which cannot run obviously. Glad you found the right file :)

ansgar's profile image ansgar posted 9 years ago Permalink

See http://www.heidisql.com/forum.php?t=21039 and r5068 - updating to the latest build should fix these "cannot find a usable libpq.dll".

ansgar's profile image ansgar posted 9 years ago Permalink

Forgot to say: You need to install the latest installer, because it contains some updated and one new dll. So, just updating to the latest heidisql.exe will not do it.

[expired user #9909]'s profile image [expired user #9909] posted 8 years ago Permalink

please put the heidisql32.r5049.exe file in the folder which contains .dll file in the db installation directory

[expired user #10312]'s profile image [expired user #10312] posted 8 years ago Permalink

This still occurs on windows 7 sp1 using the 32+64bit (yyyy_Setup.exe) installer. Uninstalling and reinstalling does not fix this. Neither does adding the HeidiSQL directory to the path and restarting. Only the yyyy-32_Setup.exe one works. Just tested this again with 9.4.0.5133 (latest nightly).

ansgar's profile image ansgar posted 8 years ago Permalink

Are you sure the latest build still yields this error?

Cannot find a usable libpq.dll

Please see my change in r5132:

Try to load libpq.dll with explicit file path if the path-less did not succeed. See http://www.heidisql.com/forum.php?t=22514

[expired user #10361]'s profile image [expired user #10361] posted 8 years ago Permalink

I'm seeing this error (on build 9.4.0.5139). It might result from trying to connect to a PostgreSQL server (Amazon Redshift) without specifying a database name in the session, but I can't consistently replicate that.

Log window says / Trying to load library with full path: C:\Program Files\HeidiSQL\libpq.dll /. The DLL file is there.

No errors connecting to a few different MySQL servers.

Running Windows 10 Pro (build 14393) on 64-bit Dell Precision M3800.

ansgar's profile image ansgar posted 8 years ago Permalink

You could uninstall Heidi, and erase the entire directory C:\Program Files\HeidiSQL\, just to be sure no dlls are left. Then do a fresh install with the latest version and try again.

[expired user #10364]'s profile image [expired user #10364] posted 8 years ago Permalink

Probably that libpq.dll is blocked by your antivirus software? I don't know. You could try on another machine. Thanks @ansgar. Same problem was happening with me. After deactivate my antivirus problem was solved.

[expired user #10614]'s profile image [expired user #10614] posted 8 years ago Permalink

I've been struggling with this as well.

I've used ProcMon and traced the issue to not having MSVCR120.dll. Upon installing "Microsoft Visual C++ 2013 Redistributable" (v 12.0.xxxx); HeidiSQL +PostgreSQL works.

CedX's profile image CedX posted 5 years ago Permalink

I encountered the same problem (HeidiSQL 10.2.0.5599 and PostgreSQL 11.4): installing "Microsoft Visual C++ 2013 Redistributable" solved it!

ansgar's profile image ansgar posted 5 years ago Permalink

Yes, that's what the download page says:

Connecting to PostgreSQL may require to have Visual C++ Redistributable Package installed

But I guess noone reads that. Maybe the HeidiSQL installer should come itself with that VC redist package and install it when not done already?

CedX's profile image CedX posted 5 years ago Permalink

Actually, I did not read everything: I clicked directly on the download link :) It may not be a bad idea to provide all the prerequisites with the installer: the error message let us think that there is a bug with HeidiSQL, not an unsatisfied dependency.

Anyway: thanks a lot for this great product!

Code modification/commit 7fd551b from Ansgar Becker <anse@heidisql.com>, 5 years ago, revision 10.2.0.5660
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
ansgar's profile image ansgar posted 5 years ago Permalink

I just pushed a change in the connection logic, which now gives the user a hint with a download url if libpq.dll cannot be loaded. This way I don't need to blow up the installer with these VC redistributables.

ansgar's profile image ansgar posted 5 years ago Permalink

Description

CedX's profile image CedX posted 5 years ago Permalink

Great idea: it's more than enough to put a link to the redistributable. Thank you again for all your efforts.

Nietenolaf's profile image Nietenolaf posted 5 years ago Permalink

Yes, great idea, BUT this is what it looks like in dark mode:
Description
All I could make out before finding this thread was the error sign and the OK button. This way I found out there's actually a solution in that box.

ansgar's profile image ansgar posted 5 years ago Permalink

You could post that image on https://github.com/RRUZ/vcl-styles-utils/issues and mention that it's a TTaskDialog with enabled tfEnableHyperlinks. HeidiSQL uses these VCL style fixes.

Please login to leave a reply, or register at first.