当前位置: 移动技术网 > IT编程>开发语言>c# > C#连接加密的Sqlite数据库的方法

C#连接加密的Sqlite数据库的方法

2019年07月18日  | 移动技术网IT编程  | 我要评论

对数据加密分两种,一种是对数据库本身进行加密,另一种是对数据表中的数据进行加密,

如果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数据库的方法,希望对大家有所帮助

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网