Can you use SQLite 64 bit odbc from powershell

Posted by Levin Magruder on Server Fault See other posts from Server Fault or by Levin Magruder
Published on 2012-06-05T22:18:48Z Indexed on 2012/06/05 22:41 UTC
Read the original article Hit count: 688

Filed under:
|
|

Basically, my question is "Does this combo work for anyone," and, "Can you see what I am doing wrong"

I have installed 64 bit ODBC driver for sqlite, downloaded from this page. I am running powershell version 2 on window 7. In ODBC configuration I create a system DSN with name LoveBoat, pointing at a valid file. I don't have any "real" apps to test whether the ODBC connection works, but a simple program I list below works. However, with PowerShell, which is what I want:

 $x = new-object System.Data.Odbc.OdbcConnection("DSN=LoveBoat")
 $x.open()

That yields the error:

 Exception calling "Open" with "0" argument(s): "The type initializer for 'System.Transactions.Diagnostics.DiagnosticTrace' threw an exception."
 At line:1 char:8
+ $x.Open <<<< ()
+ CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException

On the other hand the test program below runs and prints out the expected data.

using System.Data.Odbc;
using System.Data;
using System;

public class program
{
  public static void Main(string[] args)
  {
OdbcConnection conn = new OdbcConnection(@"DSN=LoveBoat");
conn.Open();
OdbcCommand comm = new OdbcCommand();
comm.CommandText= "SELECT Name From Myfavoritetable";
comm.Connection = conn;
 OdbcDataReader myReader = comm.ExecuteReader(CommandBehavior.CloseConnection);
 while(myReader.Read())
   {
     Console.WriteLine(myReader[0]);
   }
  }
}

© Server Fault or respective owner

Related posts about powershell

Related posts about odbc