KB0070 - Load Npgsql.dll In PowerShell Universal
Purpose
The purpose of this document is to provide information on how to load
Npgsql in PowerShell Universal's integrated environment. Npgql is a library for accessing PostgreSQL databases.
Problem
Npgsql versions are built against specific versions of .NET and need to match the version that PowerShell Universal is running.
Solution
The major versions of Npgsql are aligned with the major versions of .NET. This means that if you want to load Npgsql into a .NET process, you need to select the correct Npgsql version for that process. Every major version of PowerShell Universal uses a newer version of the .NET runtime. Below you will find a table to allow you to align the Npgsql version with the proper PowerShell Universal version. You can
download Npgsql from NuGet.
PowerShell Universal Version | .NET Version | Npgsql Version |
v3.x | v6 | 6.0.x |
v4.x | v7 | 7.0.x |
v5.x | v8 | 8.0.x |
Loading Npgsql into PowerShell Universal
You can use Import-Module to load the Npgsql.dll into a PowerShell Universal process. Below is an example of querying a database with the library.
Import-Module .\Npgsql.dll
$connectionString = "Host=localhost;Username=postgres;Password=password;Database=psu";
$Datasource = [Npgsql.NpgsqlDataSource]::Create($connectionString)
$cmd =$dataSource.CreateCommand("SELECT `"Output`" FROM `"Job`"")
$reader = $cmd.ExecuteReaderAsync().GetAwaiter().GetResult()
while ($reader.ReadAsync().GetAwaiter().GetResult())
{
$reader.GetString(0)
}
Related Articles
PowerShell Universal Service crashes on startup after an upgrade to 1.4.6
Version: PowerShell Universal 1.4.6 Issue The PowerShell Universal service will crash with the following error in Event Viewer. Application: Universal.Server.exe CoreCLR Version: 4.700.19.56402 .NET Core Version: 3.1.0 Description: The process was ...
KB0011 - Are licenses different between Production, QA and Test/Development servers?
Update January 24th, 2023 Adam recently summarized the Developer's license per below: The only real limitation on the developer license is that it cannot be accessed remotely. The server is only available on loopback when using the dev license. If ...
KB0074 - Connecting to PSU API w/Windows Auth
Scope This article applies only to PSU environments where Windows Authentication[1] is enabled and known to be working[2]. Problem You are not able to interact with the PSU instance using the Invoke-WebRequest PowerShell cmdlet even though logging in ...
KB0069 - PowerShell Universal Startup Process
Purpose The purpose of this document is to outline the steps that PowerShell Universal takes when starting up. Process 1. Insert current product version and install date in database Updates the database with a record about the current product version ...
KB0066 - Get-WMIObject cmdlet not working
Scope This article applies to any scenario where the Get-WMIObject cmdlet is expected to be available and functioning within a PowerShell Universal instance. Effectively, this article will only apply to instances that run under the Windows operating ...