Error - Generate Query PowerShell Script

This forum can be browsed by the general public. Posting is limited to current SAPIEN license holders with active maintenance and does not offer a response time guarantee.
Forum rules
DO NOT POST LICENSE NUMBERS, ACTIVATION KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM.
Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 5 years and 9 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
User avatar
Nillth
Posts: 34
Last visit: Mon Oct 30, 2023 10:52 pm
Has voted: 2 times

Error - Generate Query PowerShell Script

Post by Nillth »

Product, version and build: PowerShell Studio 2018 v5.5.152
32 or 64 bit version of product: 64 bit
Operating system: Windows 10 (1803)
32 or 64 bit OS: 64 bit

*** Please add details and screenshots as needed below. ***

In the Object Browser panel, i have selected a database I configured in Primal SQL.
from there I select a table, right click "Generate Query PowerShell Script..."
Sapien-Generate_Query_PowerShell_Script.PNG
Sapien-Generate_Query_PowerShell_Script.PNG (30.88 KiB) Viewed 1640 times

Select a name,
Save
When the script opens and I attempt to run it I get the following error


>> Running (Get-Query_Postgre_public_Users.ps1) Script...
>> Platform: V5 64Bit (STA)
>> Analyzing Script (Results in Debug pane)...
ERROR: Add-Type : Cannot add type. The assembly 'Npgsql, Version=2.0.13.91, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7' could not be found.
Get-Query_Postgre_public_Users.ps1 (9, 1): ERROR: At Line: 9 char: 1
ERROR: + Add-Type -AssemblyName 'Npgsql, Version=2.0.13.91, Culture=neutral, P ...
ERROR: + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ERROR: + CategoryInfo : ObjectNotFound: (Npgsql, Version...d8b90d52f46fda7:String) [Add-Type], Exception
ERROR: + FullyQualifiedErrorId : ASSEMBLY_NOT_FOUND,Microsoft.PowerShell.Commands.AddTypeCommand
ERROR:
ERROR: Add-Type : Cannot add type. One or more required assemblies are missing.
Get-Query_Postgre_public_Users.ps1 (9, 1): ERROR: At Line: 9 char: 1
ERROR: + Add-Type -AssemblyName 'Npgsql, Version=2.0.13.91, Culture=neutral, P ...
ERROR: + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ERROR: + CategoryInfo : InvalidData: (:) [Add-Type], InvalidOperationException
ERROR: + FullyQualifiedErrorId : ASSEMBLY_LOAD_ERRORS,Microsoft.PowerShell.Commands.AddTypeCommand
ERROR:
ERROR: New-Object : Cannot find type [Npgsql.NpgsqlCommand]: verify that the assembly containing this type is loaded.
Get-Query_Postgre_public_Users.ps1 (15, 12): ERROR: At Line: 15 char: 12
ERROR: + $command = New-Object Npgsql.NpgsqlCommand ($QueryString, $Connection ...
ERROR: + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ERROR: + CategoryInfo : InvalidType: (:) [New-Object], PSArgumentException
ERROR: + FullyQualifiedErrorId : TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand
ERROR:
ERROR: New-Object : Cannot find type [Npgsql.NpgsqlDataAdapter]: verify that the assembly containing this type is loaded.
Get-Query_Postgre_public_Users.ps1 (16, 12): ERROR: At Line: 16 char: 12
ERROR: + $adapter = New-Object Npgsql.NpgsqlDataAdapter ($command)
ERROR: + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ERROR: + CategoryInfo : InvalidType: (:) [New-Object], PSArgumentException
ERROR: + FullyQualifiedErrorId : TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand
ERROR:
ERROR: You cannot call a method on a null-valued expression.
Get-Query_Postgre_public_Users.ps1 (20, 1): ERROR: At Line: 20 char: 1
ERROR: + [void]$adapter.Fill($dataset)
ERROR: + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ERROR: + CategoryInfo : InvalidOperation: (:) [], RuntimeException
ERROR: + FullyQualifiedErrorId : InvokeMethodOnNull
ERROR:

*** PowerShell Script finished. ***
>> Execution time: < 1 second
>> Script Ended
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: Error - Generate Query PowerShell Script

Post by davidc »

The script requires the Postgre .NET provider to run. You can find the dll in PowerShell Studio's installation directory:

C:\Program Files\SAPIEN Technologies, Inc\PowerShell Studio 2018\Npgsql.dll

I recommend add it to the Global Assembly Cache so that PowerShell can locate it.
David
SAPIEN Technologies, Inc.
This topic is 5 years and 9 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.