Hi I'm trying to do a very simple program in .NET (3.1 Core or 5) something like this:
using System;
using System.Data.Odbc;
namespace testsqlite
{
class Program
{
static void Main(string[] args)
{
var conn = new OdbcConnection();
conn.ConnectionString = "Driver=SQLITE3;Database=Orders.db;LongNames=0;Timeout=1000;NoTXN=0;SyncPragma=NORMAL;StepAPI=0;";
conn.Open();
var stmt = conn.CreateCommand();
stmt.CommandText = "Select * from customer";
using (var reader = stmt.ExecuteReader())
{
var message = reader.GetString(0);
Console.WriteLine(message);
}
Console.WriteLine("Hello World!");
}
}
}
I installed sqlite3 and also installed the driver using brew install sqliteodbc
but it does now seem to work. When I run I get:Unhandled exception. System.Data.Odbc.OdbcException (0x80131937): ERROR [01000] [unixODBC][Driver Manager]Can't open lib 'SQLITE3' : file not found
Any ideas of what I might be missing?
Ok I found a way to make it work.
Before you start make sure that you have sqlite installed.
If not run brew install sqlite
.
Second install the sqlite odbc driver by running brew install sqliteodbc
NOTE: you might need to do
brew install upgrade sqliteodbc
odbcinst -j
. You do this to validate your unixODBC installation because you need to know where is the odbcinst.ini
file in your system.
For example in my case it was /usr/local/etc/odbcinst.ini
Before you edit the ini file you need to know where is the odbc library for sqlite installed. run brew test sqliteodbc
Finally modify your odbcinst.ini
to include a location for the odbc driver
After that you can just use your sqlite odbc connection string. In my case it was something like this: DRIVER=SQLITE3;Database=Orders.db; LongNames=0; Timeout=1000; NoTXN=0; SyncPragma=NORMAL; StepAPI=0;
Sometimes I have found errors when leaving spaces between
Database=
the database name and the last;
just make sure you dont because if not the driver wont find the .db file
User contributions licensed under CC BY-SA 3.0