SQLite connection in PowerShell 7

Viewed 60

PowerShell-7+

I want to create a SQLite User-defined Function (UDF) as shown in User-defined functions. The examples are in C# which I never use but would like to make it work in PowerShell. Unfortenately I cannot instantiate the SqliteConnection in PS. Here's my trivial snippet:

Add-Type -LiteralPath "path\to\Microsoft.Data.Sqlite.dll"
using namespace Microsoft.Data.Sqlite
$con = New-Object Microsoft.Data.Sqlite.SqliteConnection -ArgumentList "Data Source=hello.sqlite"

which throws this Exception

New-Object: Exception calling ".ctor" with "1" argument(s): "The type initializer for 'Microsoft.Data.Sqlite.SqliteConnection' threw an exception."

Should I use this alternate form? it also fails with same error:

$con = [Microsoft.Data.Sqlite.SqliteConnection]::new("Data Source=hello.sqlite")
MethodInvocationException: Exception calling ".ctor" with "1" argument(s): "The type initializer for 'Microsoft.Data.Sqlite.SqliteConnection' threw an exception."

I'm getting confused! What's wrong with the instanciation?

0 Answers
Related