Summary:
About the SQLite library installation is quite special:
Download address: http://system.data.sqlite.org/index.html/doc/trunk /www/downloads.wiki --ok!
https://www.sqlite.org/download.html. ---For downloading on Android, Mac, Linux and other platforms.
Download the installation package:
sqlite-netFx20-setup-bundle-x64-2005-1.0.108.0.exe --- Test ok!
Or sqlite-netFx45-setup-bundle-x64-2012-1.0.108.0.exe You need to uninstall version 2.0 first and then install it. ---Test OK!
(In order to be consistent with other software, it is recommended to install the .Net 4.5 version!)
Default installation path: C:\Program Files\System.Data.SQLite
.Net reference : Just reference the file System.Data.SQLite.dll in the installation bin directory!
Note:
1. The one with bundle means that the dynamic library is compiled in mixed mode. There are also pure x86 and pure x64 mode libraries, a total of 3 types, choose according to actual needs. (It must be consistent with the target platform when the project is generated!)
2. The downloaded library must be installed! ! (Only quoted, not installed, an error will be reported when running!!)
3. When .Net uses SQLite, you only need to quote System.Data.SQLite.dll, and sqlite3.dll is not needed at all. Didn't expect it!
SQLite Introduction:
SQLite is a lightweight database used for local data storage. Open source database.
Advantages: It occupies very low resources, requiring hundreds of K of memory in embedded devices; as a lightweight database, its processing speed is fast enough; the supported capacity level is Level T; independent: no additional dependencies; open source; supports multiple languages.
Detailed advantages:
1. Its design target is embedded, and it occupies very low resources. In embedded devices, only a few hundred K of memory may be enough. .
2. Cross-platform and multi-language support: It can support mainstream operating systems such as Windows/Linux/Unix, and can be combined with many programming languages,
such as C, C, PHP, Perl , Java, C#, Python, Ruby, etc.
3. Fast speed: Compared with Mysql and PostgreSQL, two world-famous open source database management systems, its processing speed is faster than them.
(It is faster than some popular databases in most ordinary database operations.)
4. Supports database size up to 2TB.
5. Small enough, about 130,000 lines of C code, 4.43M
6. Simple, easy API
7. The source code is completely open source, you can use it Any purpose, including selling it.
8. It also supports transaction processing functions and so on.
Use .NET to operate SQLLITE:
Sample code 1:
public string Query() { string datasource = "e:/tmp/test.db"; System.Data.SQLite.SQLiteConnection.CreateFile(datasource); //连接数据库 System.Data.SQLite.SQLiteConnection conn = new System.Data.SQLite.SQLiteConnection(); System.Data.SQLite.SQLiteConnectionStringBuilder connstr = new System.Data.SQLite.SQLiteConnectionStringBuilder(); connstr.DataSource = datasource; connstr.Password = "admin";//设置密码,SQLite ADO.NET实现了数据库密码保护 conn.ConnectionString = connstr.ToString(); conn.Open(); //创建表 System.Data.SQLite.SQLiteCommand cmd = new System.Data.SQLite.SQLiteCommand(); string sql = "CREATE TABLE test(username varchar(20),password varchar(20))"; cmd.CommandText = sql; cmd.Connection = conn; cmd.ExecuteNonQuery(); //插入数据 sql = "INSERT INTO test VALUES('a','b')"; cmd.CommandText = sql; cmd.ExecuteNonQuery(); //取出数据 sql = "SELECT * FROM test"; cmd.CommandText = sql; System.Data.SQLite.SQLiteDataReader reader = cmd.ExecuteReader(); StringBuilder sb = new StringBuilder(); while (reader.Read()) { sb.Append("username:").Append(reader.GetString(0)).Append("\n") .Append("password:").Append(reader.GetString(1)); } //MessageBox.Show(sb.ToString()); return sb.ToString(); }
Sample code 2: Transaction operation:
using (SQLiteConnection conn = new SQLiteConnection(connectionString)) { conn.Open(); SQLiteCommand cmd = new SQLiteCommand(); cmd.Connection = conn; SQLiteTransaction tx = conn.BeginTransaction(); cmd.Transaction = tx; try { for (int n = 0; n < SQLStringList.Count; n++) { string strsql = SQLStringList[n].ToString(); if (strsql.Trim().Length > 1) { cmd.CommandText = strsql; cmd.ExecuteNonQuery(); } } tx.Commit(); } catch (System.Data.SQLite.SQLiteException E) { tx.Rollback(); throw new Exception(E.Message); }
Related articles:
Using SQLite relational database
How to use MySQL database in .NET
Related videos:
The above is the detailed content of What are the detailed advantages of operating SQLite database in .Net?. For more information, please follow other related articles on the PHP Chinese website!