Jaki jest najlepszy sposób podłączenia i korzystania z bazy danych sqlite z C#

Robiłem to już wcześniej w C++ włączając w to sqlite.h ale czy jest podobnie łatwy sposób w C#?

 39
Author: Richard Gourlay, 2008-08-25

8 answers

ADO.NET 2.0 Provider dla SQLite ma ponad 200 pobrań dziennie, więc myślę, że jesteś bezpieczny przy użyciu tego.

 39
Author: Espo,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-04-15 05:25:31

Zgadzam się, Bruce. Używam http://system.data.sqlite.org z wielkim sukcesem. Oto prosty przykład klasy, który stworzyłem:

using System;
using System.Text;
using System.Data;
using System.Data.SQLite;

namespace MySqlLite
{
      class DataClass
      {
        private SQLiteConnection sqlite;

        public DataClass()
        {
              //This part killed me in the beginning.  I was specifying "DataSource"
              //instead of "Data Source"
              sqlite = new SQLiteConnection("Data Source=/path/to/file.db");

        }

        public DataTable selectQuery(string query)
        {
              SQLiteDataAdapter ad;
              DataTable dt = new DataTable();

              try
              {
                    SQLiteCommand cmd;
                    sqlite.Open();  //Initiate connection to the db
                    cmd = sqlite.CreateCommand();
                    cmd.CommandText = query;  //set the passed query
                    ad = new SQLiteDataAdapter(cmd);
                    ad.Fill(dt); //fill the datasource
              }
              catch(SQLiteException ex)
              {
                    //Add your exception code here.
              }
              sqlite.Close();
              return dt;
  }
}

Istnieje również pakiet NuGet: System.Data.SQLite Dostępny.

 62
Author: DA.,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-11-03 19:31:14

Używałem tego z wielkim sukcesem:

Http://system.data.sqlite.org/

Za darmo bez ograniczeń.

(uwaga z recenzji: oryginalna strona już nie istnieje. Powyższy link ma link wskazujący stronę 404 i zawiera wszystkie informacje o oryginale)

--Bruce

 12
Author: bvanderw,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-04-25 21:35:45

Lista wrapperów SQLite dla. Net znajduje się pod http://www.sqlite.org/cvstrac/wiki?p=SqliteWrappers . z tego co słyszałem http://sqlite.phxsoftware.com / jest całkiem dobry. Ten konkretny pozwala uzyskać dostęp do Sqlite poprzez ADO.Net jak każda inna baza danych.

 7
Author: robintw,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2008-08-25 13:29:44

Jest też teraz ta opcja: http://code.google.com/p/csharp-sqlite/ - Kompletny port SQLite do C#.

 5
Author: xanadont,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2009-08-07 15:16:00

Https://github.com/praeclarum/sqlite-net jest teraz prawdopodobnie najlepszą opcją.

 4
Author: xanadont,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-06-20 14:15:54

Innym sposobem wykorzystania bazy danych SQLite w NET frameworku jest użycie Fluent-NHibernate .
[Jest to moduł sieciowy, który otacza NHibernate (ORM module - Object Relational Mapping) i pozwala na programową konfigurację NHibernate (bez plików XML)z płynnym wzorcem.]

Oto krótki opis jak to zrobić w C# krok po kroku:

Https://github.com/jagregory/fluent-nhibernate/wiki/Getting-started

Zawiera kod źródłowy jako projekt Visual Studio.

 3
Author: Bronek,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-05-02 21:11:17

Mono jest w opakowaniu, użyj ich!

Https://github.com/mono/mono/tree/master/mcs/class/Mono.Data.Sqlite/Mono.Data.Sqlite_2.0 daje kod do zawijania rzeczywistej biblioteki dll SQLite ( http://www.sqlite.org/sqlite-shell-win32-x86-3071300.zip znalezione na stronie pobierania http://www.sqlite.org/download.html / ) w sposób przyjazny dla.Net. Działa na Linuksie lub Windows.

Wydaje się to najcieńsze ze wszystkich światów, minimalizując zależność od bibliotek stron trzecich. Gdybym miał zrobić ten projekt od podstaw, zrobiłbym to w ten sposób.

 1
Author: Limited Atonement,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-07-25 22:35:19