对数据加密分两种,一种是对数据库本身进行加密,另一种是对数据表中的数据进行加密,
如果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数据库的方法,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对服务器之家网站的支持!
原文链接:http://HdhCmsTestcnblogs测试数据/LittleFeiHu/archive/2017/08/03/7279259.html
dy("nrwz");
查看更多关于C#连接加密的Sqlite数据库的方法的详细内容...