Page 1 of 1

Problem accessing a SQLite DB within Powershell script

Posted: Wed Oct 14, 2015 7:32 am
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

Problem accessing a SQLite DB within Powershell script

Posted: Wed Oct 14, 2015 7:32 am
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 ***

Re: Problem accessing a SQLite DB within Powershell script

Posted: Wed Oct 14, 2015 7:47 am
by jvierra
Are you building for the correct version? Can you run the script in PowerShell Studio? Are you using the correct host?

Re: Problem accessing a SQLite DB within Powershell script

Posted: Wed Oct 14, 2015 8:13 am
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.

Re: Problem accessing a SQLite DB within Powershell script

Posted: Wed Oct 14, 2015 9:10 am
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.

Re: Problem accessing a SQLite DB within Powershell script

Posted: Wed Oct 14, 2015 7:24 pm
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.

Re: Problem accessing a SQLite DB within Powershell script

Posted: Wed Oct 14, 2015 11:28 pm
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")
		}

Re: Problem accessing a SQLite DB within Powershell script

Posted: Thu Oct 15, 2015 12:06 am
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

Re: Problem accessing a SQLite DB within Powershell script

Posted: Thu Oct 15, 2015 2:26 am
by ralf_jantschek
Hi,
sorry I forgot to mention, but I already tried and it works from the Commandline as well

Re: Problem accessing a SQLite DB within Powershell script

Posted: Thu Oct 15, 2015 2:31 am
by jvierra
Are you trying too run this in a form?