Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQLite on C# Cross-Platform Applications

Can someone help/guide me with using SQLite lib on Linux (MONO) and Windows (.NET)

On linux i use native mono sqlite client, and on windows i use http://sqlite.phxsoftware.com/

is there a way to define 'using' directives like this :

#if (linux)
  using Mono.Data.Sqlite;
#else
  using System.Data.SQLite;

Another problem is small differencies on both implementations, like :

cmd = new SqliteCommand(); // mono
cmd = new SQLiteCommand(); // sqlite.phxsoftware.com

Waiting for any help

If you know better or simplier way to do this it'll very thankfull for info.

Thanks

like image 382
alienn Avatar asked Mar 08 '10 10:03

alienn


2 Answers

You can use csharp-sqlite which is a port to C# of Sql-Lite. It is very active and based on 3.6.22 version of SqlLite. See Miguel's comments on attempts to try to speed it up.

like image 50
Kris Erickson Avatar answered Sep 28 '22 04:09

Kris Erickson


I've recently come across the issue too: building an application that uses Sqlite on Windows with Visual Studio and deploying it on an Ubuntu Server box for production.

The simplest solution I've found is using the Mono driver for Sqlite: Mono.Data.Sqlite.

Things could have been a little simpler but there is a bug with .Net 4.0 that is not yet packaged in the official Mono releases.

So you'll have to compile Mono from source (the general instructions are here):

  • first compile the whole Mono stuff
  • you do not need to install it if you want to keep your current Mono setup
  • copy the Mono.Data.Sqlite.dll library

Of course you can "cross-compile": I've built Mono on Ubuntu Server and used the dll in a Windows .Net project.

Then ensure you have the native Sqlite library (sqlite3.dll for Windows and sqlite3.so for Linux) in your library path: for Windows I simply copied the sqlite3.dll next to the Mono.Data.Sqlite.dll assembly, for Linux it should work out of the box.

You project should then work seamlessly in both Windows/.Net and Linux/Mono environments.

like image 32
Pragmateek Avatar answered Sep 28 '22 04:09

Pragmateek