distal-attribute
distal-attribute
distal-attribute
distal-attribute

Cannot find a usable libpq.dll

jamesvl posted 2 years ago in Creating a connection

I saw from the forums that this was an issue a while ago, but I'm getting it again with the latest builds of HeidiSQL and a clean install of Windows 10.

The error dialog states "Cannot find a usable libpq.dll. Please launch heidisql.exe from a directory where you installed it.

  • I've verified that that libpq, libeasy 32, and ssleay32 .dlls are all present.
  • I am launching from the directory that I installed it.
  • I tried it from both the Program Files directory and installed in a non-protected directory.
  • It occurs whether I try to run as Administrator or not.
  • This is the 64 bit version of Windows 10.
  • I've seen this issue now from any clean install of Windows 10, whether through VirtualBox or natively on a new PC.

Any tips or ideas on how to work around this?

ansgar posted 2 years ago

Can you please - just for testing purposes - download and run the portable version of HeidiSQL? The portable version just contains the 32bit version of heidisql.exe and all .dll's. So we can probably track down the problem to 32/64bit.

jamesvl posted 2 years ago

Just tried, and I'm getting the same error, unfortunately.

ansgar posted 2 years ago

Heidi loads libpq.dll without a path, so that might be a problem when there is a different libpq.dll somewhere else in the %path%. I could try and let Heidi load libpq.dll from exactly the folder where the current heidisql.exe is running from.

ansgar posted 2 years ago

Please try that in r5065.

jamesvl posted 2 years ago

I tried 5065 - still getting the same error.

I also tried adding the HeiSQL path to my PATH environment variables - still the same result.

Not sure why this is happening now - the version I run at home (which I installed a long while ago, but have used the update process to keep current) runs just fine there. When I moved that full install directory to the new machine, I get the same error. (But that doesn't cover any confounding variables, like other software or Postgres server installed at home.)

ansgar posted 2 years ago

Sorry for the mess. Got no more ideas currently, only I know you're not the only one having this issue: http://www.heidisql.com/forum.php?t=18580 http://www.heidisql.com/forum.php?t=20693

r5066 adds the last system error message to the "cannot find a usable libpq.dll" dialog. Probably this is helpful for finding some error here. Please update again.

jamesvl posted 2 years ago

I tried version 5066 on fresh install for Windows 10 Pro x64 (only other thing installed are VirtualBox extensions), but still got the same error, with the additional info that "The operation completed successfully".

I ran Sysinternal Process Monitor on my working machine and the new machine, and have attached screenshots of the results. If you'd like a stack trace of any particular call, I can also attach those.

2 attachment(s):
  • working_pgsql_proc_calls
  • broken_libpq_proc_calls
ansgar posted 2 years ago

Looks like the dll was loaded but the result of LoadLibrary() is 0 anyway, which normally means: dll could not be loaded. So, I could just check the existence of libpq.dll without checking the result of LoadLibrary. This evening...

ansgar posted 2 years ago

r5067 now does only a FileExists() check on libpq.dll in the HeidiSQL directory. No check for what LoadLibrary() returns. This can cause crashes but it may also fix this issue.

jamesvl posted 2 years ago

Sorry, no luck on 5067 either. This is really confusing to me.

It now says, "Your libpq.dll is out-dated or somehow incompatible to HeidiSQL. Please use the one from the installer, or just reinstall HeidiSQL."

(Got this from both manually downloading and adding the 5067 x64 executable, and then uninstalling and doing a fresh install with the 5067 isntaller.)

ansgar posted 2 years ago

With the latest build, could you activate debug logging (in Tools > Preferences > Logging), then connect to some working (maybe MySQL or MSSL) session, then attempt to connect to your PostgreSQL server. The log should display now a number of such lines:

Assign procedure "PQconnectdb"

I guess it will just be one of these lines, but just to be sure it's not some special procedure which is not working.

jamesvl posted 2 years ago

Haven't tried iwth local MySQL yet, but will in a second. Getting this from Postgres:

/* 2016-04-06 12:13:15 [DB] */ /* Loading library file C:\Program Files\HeidiSQL\libpq.dll ... */
/* 2016-04-06 12:13:15 [DB] */ /* Assign procedure "PQconnectdb" */
/* 2016-04-06 12:13:15 [DB] */ /* Library error in libpq.dll: Could not find procedure address for "PQconnectdb" */
jamesvl posted 2 years ago

MySQL is working fine. Sometimes, my Postgres connection stop logging before it gets to the end of its output:

/* 2016-04-06 12:19:14 [] */ /* Writing to session log file now: Z:\heidisql.log\000003.log */
/* 2016-04-06 12:19:14 [] */ /* Setting up TSynMemo "SynMemoQuery" */
/* 2016-04-06 12:19:14 [] */ /* Setting up TSynMemo "SynMemoFilter" */
/* 2016-04-06 12:19:14 [] */ /* Setting up TSynMemo "SynMemoProcessView" */
/* 2016-04-06 12:19:14 [] */ /* Setting up TSynMemo "SynMemoSQLLog" */
/* 2016-04-06 12:20:23 [MySQL Test] */ /* Loading library file libmysql.dll ... */
/* 2016-04-06 12:20:23 [MySQL Test] */ /* Assign procedure "mysql_affected_rows" */
...
/* 2016-04-06 12:20:23 [MySQL Test] */ /* libmysql.dll v5.6.6-m9 loaded. */
/* 2016-04-06 12:20:23 [MySQL Test] */ /* Connecting to 172.16.26.87 via MySQL (TCP/IP), username root, using password: Yes ... */
...
/* 2016-04-06 12:20:47 [] */ /* DBtreeFocusChanged without node. */
/* 2016-04-06 12:20:52 [PGDB] */ /* Loading library file C:\Program Files\HeidiSQL\libpq.dll ... */
/* 2016-04-06 12:20:52 [AMG [dev vm]] */ /* Library error in libpq.dll: Could not find procedure address for "PQconnectdb" */
[tried to connect again]
/* 2016-04-06 12:23:00 [AMG [dev vm]] */ /* Loading library file C:\Program Files\HeidiSQL\libpq.dll ... */
/* 2016-04-06 12:23:00 [AMG [dev vm]] */ /* Assign procedure "PQconnectdb" */
/* 2016-04-06 12:23:00 [AMG [dev vm]] */ /* Library error in libpq.dll: Could not find
ansgar posted 2 years ago

Hm, well, that still means the dll cannot be loaded.

I should definitely check if I mixed up the 32/64bit libpq.dll's in the installer...

If you have the time you can try to copy libpq.dll from the Windows PostgreSQL server download. I will do the same this evening.

jamesvl posted 2 years ago

Tried replacing with the libpq version that ships with the latest pgAdmin III - still not luck.

I tried with the 64 & 32-bit (only) HeidiSQL installers, got the same error message about loading the .dll.

jamesvl posted 2 years ago

I just tried a bunch more combinations - and finally got it to work! But it requires replacing every one of the library .dlls with a more recent version. (Or versions that know about each other?)

Here's what I did:

  1. Tried copying the heidisql.exe (64-bit version) into my PostgreSQL\9.5\bin directory (I did a fresh 9.5.2 Windows server install); running Heidi from there worked!
  2. Tried copying the same .exe plus 4 .dlls from PostgreSQL\9.5\bin (libeay32, libintl-8, libpq, and ssleay32) to own, new directory - it didn't work. (got same error as always)
  3. Copied .dlls one by one from Posgres\9.5\bin to the new directory - it worked after I added libiconv-2.dll
  4. Tried copying only libiconv-2.dll to my original HeidiSQL location - that didn't work.
  5. Replaced, one by one, the other 4 .dlls - none of them helped, and I only once got another error about a dll not finding a symbol it expected. Once all original .dlls were replaced, and libiconv-2 was added (just like in #3), it finally worked from original install location.
ansgar posted 2 years ago

Oh man, thanks for your effort and consistent feedback :)

So, libiconv-2.dll is missing and all other dlls should be updated if I understand right. Will check that here as soon as I can.

jamesvl posted 2 years ago

You're welcome - I'm really glad for the tool you've made and continue to work on!

And your summary is correct, and a much more succinct way to summarize what I found. :)

Disclaimer: I only tested those results with the 64-bit version of Heidi and the 64-bit dlls from the Postgres install. But it worked again fine when I re-did the steps on my office machine.

ansgar posted 2 years ago

So, all above mentioned changes done in r5068. Also, I reverted the previous 3 commits, as I think these changes did not help anyway and they are most likely not required any longer.

For me it (still) works, also with a fresh install of the 64bit installer.

jamesvl posted 2 years ago

Yep, 5068 just worked for me on a fresh install!

ansgar posted 2 years ago

Coool! :)

I'm gonna have 3 or 4 beers on that this evening.

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