Problem accessing a SQLite DB within Powershell script

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

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 8 years and 5 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.
Locked
User avatar
ralf_jantschek
Posts: 17
Last visit: Tue May 30, 2023 2:49 am

Problem accessing a SQLite DB within Powershell script

Post by ralf_jantschek »

Hello,

I'm writing a script that needs to store information in a SQLite DB.
What i did so far is:

Code: Select all

[void][System.Reflection.Assembly]::LoadFrom("D:\Program Files\System.Data.SQLite\2008\bin\x32\System.Data.SQLite.dll")

$cn = New-Object -TypeName System.Data.SQLite.SQLiteConnection

$cm = New-Object -TypeName System.Data.SQLite.SQLiteCommand
This code works fine inside the IDE. As soon as i try this in the complied EXE the Objects $cn and $cm are empty and the Windows Eventlog tells me:
Error Message = Cannot find type [System.Data.SQLite.SQLiteConnection]: verify that the assembly containing this type is loaded.
Fully Qualified Error ID = TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand
My Config W7 SP1 64Bit; Powershell 4.0

I hope my description is sufficient.

Any Help is very welcome!

Thank you
Ralf
User avatar
SAPIEN Support Forums
Posts: 945
Last visit: Thu Oct 22, 2015 1:10 pm

Problem accessing a SQLite DB within Powershell script

Post by SAPIEN Support Forums »

This is an automated post. A real person will respond soon.

Thank you for posting, Ralfii.

Here are some hints to help you get an accurate and complete answer to your question.

Ask in the best forum: If you asked in the wrong forum, just copy your question to the right forum.

Anticipate follow-up questions!

Did you remember to include the following?
  • 1. Product, version and build
    2. 32 or 64 bit product
    3. Operating system, e.g. Windows 7 64 bit.
    4. Attach a screenshot, if applicable
    5. Attach logs, crash reports, etc., in a ZIP file
If not, please take a moment to edit your original post or reply to this one.

*** Make sure you do not post any licensing information ***
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Problem accessing a SQLite DB within Powershell script

Post by jvierra »

Are you building for the correct version? Can you run the script in PowerShell Studio? Are you using the correct host?
User avatar
ralf_jantschek
Posts: 17
Last visit: Tue May 30, 2023 2:49 am

Re: Problem accessing a SQLite DB within Powershell script

Post by ralf_jantschek »

I tried all versions i could choose from
v2 - 32
v2 - 64
v4 - 32
v4 - 64
none worked in the compiled version.
Yes, as mentioned it works perfect inside the IDE.

What exactly do you mean by Host? the DB resides on my local PC.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Problem accessing a SQLite DB within Powershell script

Post by jvierra »

That doesn't tell us what host you are using in the build. Look at the list of build hosts.

Look under "settings" at the "Platform" setting.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Problem accessing a SQLite DB within Powershell script

Post by jvierra »

If you re running 64 bit PowoerShell then you are loading the wrong assembly:

[void][System.Reflection.Assembly]::LoadFrom("D:\Program Files\System.Data.SQLite\2008\bin\x32\System.Data.SQLite.dll")

This is the 2 bit version.
User avatar
ralf_jantschek
Posts: 17
Last visit: Tue May 30, 2023 2:49 am

Re: Problem accessing a SQLite DB within Powershell script

Post by ralf_jantschek »

I'm using the only host that is on offer "localhost"
as already mentioned i tried ALL available Platforms:
I tried all versions i could choose from
v2 - 32
v2 - 64
v4 - 32
v4 - 64
and this is only a snippet not the whole code.

Code: Select all

try
		{
		[void][System.Reflection.Assembly]::LoadFrom("D:\Program Files\System.Data.SQLite\2008\bin\x32\System.Data.SQLite.dll")
			

		}
		catch
		{
			[void][System.Reflection.Assembly]::LoadFrom("C:\Program Files\System.Data.SQLite\2008\bin\x64\System.Data.SQLite.dll")
		}
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Problem accessing a SQLite DB within Powershell script

Post by jvierra »

If you open a powershell prompt (CLI) and run the connection code what happens?

Just do this at a prompt:

PowerShell Code
Double-click the code block to select all.
[System.Reflection.Assembly]::LoadFrom("C:Program FilesSystem.Data.SQLite2008binx64System.Data.SQLite.dll")

$cn = New-Object System.Data.SQLite.SQLiteConnection
User avatar
ralf_jantschek
Posts: 17
Last visit: Tue May 30, 2023 2:49 am

Re: Problem accessing a SQLite DB within Powershell script

Post by ralf_jantschek »

Hi,
sorry I forgot to mention, but I already tried and it works from the Commandline as well
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Problem accessing a SQLite DB within Powershell script

Post by jvierra »

Are you trying too run this in a form?
This topic is 8 years and 5 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.
Locked