In C #, how do I connect to an encrypted Sqlite database,
There are two types of data encryption: one is to encrypt the database itself, and the other is to encrypt the data in the data table,
If the SQLite database is encrypted, one of the management tools I use here is SQLiteDeveloper. You can encrypt the database as follows:
,
If you open the database without providing a password in the tool, the following error message is displayed:
,
Or if you use the wrong password in C #, the following error message is displayed:
System. Data. SQLite. SQLiteException: "file is encrypted or is not a database
,
The correct connection method is to provide the correct password in the connection string:
using System;using System.Collections.Generic;using System.Data.SQLite;using System.Linq;using System.Text;using System.Threading.Tasks;namespace OpenSqliteDBByPwd{ class Program { static void Main(string[] args) { string DB_PATH = "Data Source=EncryptedDB.db3; Password=1111"; using (SQLiteConnection con = new SQLiteConnection(DB_PATH)) { con.Open(); string sqlStr = @"INSERT INTO Customer(CUST_NO,CUSTOMER) VALUES ( 3001, 'Allen' )"; using (SQLiteCommand cmd = new SQLiteCommand(sqlStr, con)) { cmd.ExecuteNonQuery(); } } } }}