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.
Locked
User avatar
ralfii
Posts: 10
Joined: Sun Mar 03, 2013 12:44 pm

Problem accessing a SQLite DB within Powershell script

Post by ralfii »

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
Joined: Wed Dec 03, 2014 2:26 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: 14614
Joined: Tue May 22, 2007 9:57 am
Answers: 2
Has voted: 1 time
Been upvoted: 3 times
Contact:

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
ralfii
Posts: 10
Joined: Sun Mar 03, 2013 12:44 pm

Re: Problem accessing a SQLite DB within Powershell script

Post by ralfii »

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: 14614
Joined: Tue May 22, 2007 9:57 am
Answers: 2
Has voted: 1 time
Been upvoted: 3 times
Contact:

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: 14614
Joined: Tue May 22, 2007 9:57 am
Answers: 2
Has voted: 1 time
Been upvoted: 3 times
Contact:

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
ralfii
Posts: 10
Joined: Sun Mar 03, 2013 12:44 pm

Re: Problem accessing a SQLite DB within Powershell script

Post by ralfii »

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: 14614
Joined: Tue May 22, 2007 9:57 am
Answers: 2
Has voted: 1 time
Been upvoted: 3 times
Contact:

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
ralfii
Posts: 10
Joined: Sun Mar 03, 2013 12:44 pm

Re: Problem accessing a SQLite DB within Powershell script

Post by ralfii »

Hi,
sorry I forgot to mention, but I already tried and it works from the Commandline as well

jvierra
Posts: 14614
Joined: Tue May 22, 2007 9:57 am
Answers: 2
Has voted: 1 time
Been upvoted: 3 times
Contact:

Re: Problem accessing a SQLite DB within Powershell script

Post by jvierra »

Are you trying too run this in a form?

Locked