對數據加密分兩種,一種是對數據庫本身進行加密,另一種是對數據表中的數據進行加密,
如果SQLite數據庫加密,我這里使用的一個管理工具叫SQLiteDeveloper,如下就可以加密數據庫
,
如果在工具中不提供密碼的情況下打開數據庫,會給你錯誤提示如下:
,
或者在C# 使用錯誤的密碼也會給你錯誤提示:
System.Data.SQLite.SQLiteException:“file is encrypted or is not a database
,
正確的連接方式就是在連接字符串中提供正確的密碼:
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();        }      }    }  }}總結
以上所述是小編給大家介紹的C#連接加密的Sqlite數據庫的方法,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對武林網網站的支持!
新聞熱點
疑難解答