September 26, 2009 by Ivan
[HowTo] Use SqLite ADO.NET with C#
SQLite is software library written in C that implement self-contained (very minimal support from external libraries), serverless (read/write process directly to database file), cross-platform (run in any Operating System), zero-configuration (no setup/installation needed), transactional (implement serializeable transaction) SQL database engine. SQLite is relatively small, approx 275 KB in size and single database file.
For me SQLite is better solution rather than use MS.Access for medium to small scale application, because it cross-platform and i don’t need to install Microsoft Office in client computer. And because it doesn’t need any configuration, just plug and play application and run anywhere. Such a convenient. And also SQLite support custom function and trigger function. In Ms.Access you need to write your custom function in VBA, but in SQLite you can write your custom function in your own language and later it will automatically bind to SQLite process.
Advantage of SQLite:
1. Zero-Configuration
2. Serverless
3. Single Database File
4. Stable Cross Platform Database File
5. Compact Size
6. Variable-length records
7. Free with Public Domain license
Disadvantage of SQLite:
1. In most case database size is restricted to 2GB
2. Not fully SQL92 compliant
3. Lock whole file while writing
4. No caching mechanism
5. Not very scalable
Next is i will show you how to use SQLite with C# programming language. To access SQLite in C# you need to use SQLite ADO.NET that you can download here. And now follow this instruction:
1. Open your Visual Studio 2005/2008 (I’m using 2008 express)
2. Create C# project, you can call it “SqliteTest”

3. Import the dlls from sqlite ADO.NET (System.Data.SQLite.dll)
4. Change the “Copy Local” property of System.Data.SQLite.dll to true, so this dll will be copied when compiled

5. Then Add new folder called Data, we are going to put the database file here.
6. Add the database file, then change the ”Copy To Output Directory” property to “Always”

7. Now select the form1 design and insert a DataGridView, adjust the properties as you like

8. Double click Form1 so you will go to text editor and in Form1_Load events
9. Add this code:
private void Form1_Load(object sender, EventArgs e) { SQLiteConnection ObjConnection = new SQLiteConnection("Data Source=Data/data.db3;"); SQLiteCommand ObjCommand = new SQLiteCommand("SELECT * FROM PERSON", ObjConnection); ObjCommand.CommandType = CommandType.Text; SQLiteDataAdapter ObjDataAdapter = new SQLiteDataAdapter(ObjCommand); DataSet dataSet = new DataSet(); ObjDataAdapter.Fill(dataSet, "Person"); dataGridView1.DataSource = dataSet.Tables["Person"]; }
10. And the last thing don’t forget to add this code to the top of the file:
using System.Data.SQLite;
11. Compile and running the file. And you are connected to SQLite database. You can do any experiment like Insert, Update and Delete operation or do other complex query.

You can download the example project and database file from those instruction above here.
Thanks for reading this article, please leave me any comment or any tips you would like to share. Good luck.





you have a typo: you mean DISadvantages of SQLite for the one heading…
Yes, thank you charlie.
My bad. Sorry…
Try EffiProz Database http://www.EffiProz.com,
EffiProz is a database written entirely in C#. comprehensive SQL support including Stored Procedures, Triggers and Functions. Ideal for embed in .Net applications. Support Silverlight 3 and .Net compact framework as well
Include Visual Studio ad-in, ADO.Net provider, Entity Framework provider, etc.
Thanks, i’ll give it a look.