How can I access SQLite with C#?
You can not connect to sqlite db using SQLProvider classes. They are for sql server. You need to use SQLite provider classes.
- Download the appropriate distribution from http://system.data.sqlite.org/index.html/doc/trunk/www/downloads.wiki
- Reference
System.Data.SQLite.DLL
in your project (this gives you the SQLiteConnection class) Connect with
SQLiteConnection connection = new SQLiteConnection(@"DbLinqProvider=Sqlite;Data Source=Database.s3db"); Main main = new Main(connection);
See https://code.google.com/p/dblinq2007/wiki/Installation#To_use_DbLinq for details.
SQLite in C# (requires System.Data.SQLite
in references)
// Required references, after installing SQLite via Nuget
using System.Data.SQLite;
using System.Data.Common;
// Example usage in code...
SQLiteConnection db = new SQLiteConnection("Data Source=C:\LocalFolder\FooBar.db;FailIfMissing=True;");
db.Open();
using (SQLiteCommand comm=db.CreateCommand()) {
comm.CommandText = requete_sql;
IDataReader dr=comm.ExecuteReader();
while (dr.Read())
{
//...
}
}
There's an article on MSDN magazine about just that:
http://msdn.microsoft.com/en-us/magazine/ff898405.aspx