How to use PostgreSQL inside a script or page

Product: PowerShell Universal
Version: 5.6.13

I’m trying to use PostgreSQL as a data source for my script in Universal via Npgsql.
The data resides on another server then the one where PSU is running on.
I run PSU inside a docker container.

Looking at this page:

I see that PSU v5 should run on .NET 8.
However, looking at this page:

I see that v5 uses .NET 9

I could not get Install-Package to run inside the container so I copied the DLL files to the container itself:
/root/packages/Microsoft.Extensions.Logging.Abstractions.10.0.2
/root/packages/Npgsql.10.0.1

PS: the issue I got when I tried to install the packages:
Install-Package: Package ‘Npgsql’ failed to be installed because: End of Central Directory record could not be found.

The when trying to load the the types/DLL’s like this:
Add-Type -Path “/root/packages/Microsoft.Extensions.Logging.Abstractions.10.0.2/lib/net8.0/Microsoft.Extensions.Logging.Abstractions.dll”
Add-Type -Path “/root/packages/Npgsql.10.0.1/lib/net8.0/Npgsql.dll”

I get these errors:
Could not load file or assembly '/root/packages/Microsoft.Extensions.Logging.Abstractions.10.0.2/lib/net8.0/Microsoft.Extensions.Logging.Abstractions.dll'. The located assembly's manifest definition does not match the assembly reference. (0x80131040)
Could not load file or assembly '/root/packages/Npgsql.10.0.1/lib/net8.0/Npgsql.dll'. The located assembly's manifest definition does not match the assembly reference. (0x80131040)

PS: I did try to load the .NET 9 versions of these files as well, same issues.

When I set the Execution Environment to “Powershell 7” I only see the error for “Microsoft.Extensions.Logging.Abstractions.10.0.2”
When I use the default “Integrated” environment I get messages for both DLL’s

I did go into the container and started a Powershell session, load the DLL’s and started querying the DB. It worked fine. I could load the .NET 8 versions of these DLL’s and got no complaints at any moment.

My questions are these:

  • How do I properly install all packages in PSU in order to use Npgsql?
  • How can I have PSU load these automatically when PSU starts?
    The idea being that this should be available by default as multiple locations (scripts, pages, dashboards) should and will use PostgreSQL data and having these packages readily available in any script would be nice
  • What is the best or recommended way to (re)use connections?
    Do I create a new connection in every script or is there some clever way to ‘share’ connections, and should I even want that? :slight_smile:

Cheers!

Steven

Npgsql has a very low user base. I see almost zero documentation. Personally, expect issues.