对数据加密分两种,一种是对数据库本身进行加密,另一种是对数据表中的数据进行加密,下面通过本文给大家介绍c#连接加密的sqlite数据库的方法,感兴趣的朋友一起看看吧
对数据加密分两种,一种是对数据库本身进行加密,另一种是对数据表中的数据进行加密,
如果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)的示例分享的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号