system.data.sqlite有使用密码的功能。conn是SQLiteConnection 类的对象,则第一次使用时先open数据库文件, 然后使用 conn.ChangePassword("密码"); 设置数据库文件的密码。(changepassword方法必须在open之后才可以用) 以后打开数据库文件的时候,要先使用 conn.SetPassword("密码"); 来输入数据库文件的秘密,然后才可以打开。(setpassword方法必须在open之前使用) 楼主你第二次打开数据库文件依然使用changepassword当然会报错 File opened that is not a database file file is encrypted or is not a database changepassword是没有密码,设置密码,或者改变密码时用的,必须先open才可以。
我举个例子SQLServer的数据库你有办法让它不能随便打开吗?
需要连接到SQL的服务器,设置了登陆密码什么的还需要密码可是SQLite就是个文件
http://liuleijsjx.javaeye.com/blog/424705
SQLiteConnectionStringBuilder builder = new SQLiteConnectionStringBuilder();
SQLiteConnection Conn = new SQLiteConnection();
string GetPath = @"...ConfigDB.s3db";
/// <summary>
/// 创建数据库密码
/// </summary>
public void SqliteCreate()
{
try
{
builder.DataSource = GetPath;
Conn.ConnectionString = builder.ConnectionString;
if (Conn != null && Conn.State == ConnectionState.Closed)
{ Conn.Open(); }
Conn.ChangePassword("123456");
}
catch (Exception e)
{
throw e;
}
}
可是这样出现了问题
File opened that is not a database file
file is encrypted or is not a database
好像还要装SQLite-1.0.65.0-setup.exe这个东西吧
file is encrypted or is not a database
using (System.Data.SQLite.SQLiteConnection cnn = new System.Data.SQLite.SQLiteConnection())
{
using (System.Data.SQLite.SQLiteCommand cmd = new System.Data.SQLite.SQLiteCommand())
{
string cnnstr = @"data source=E:\sql.db;Version=3;Password=aaaa;";
cnn.ConnectionString = cnnstr;
if (cnn.State != ConnectionState.Open)
cnn.Open();
cmd.CommandText = "Select * from TB1";
cmd.Connection = cnn;
System.Data.SQLite.SQLiteDataReader rd = cmd.ExecuteReader(); while (rd.Read())
{
if (record.Length > 0)
record += "\r\n";
record += (rd[0] is DBNull) ? string.Empty : rd[0].ToString();
record += (rd[1] is DBNull) ? string.Empty : "\t" + rd[1].ToString();
}
}
}
if (record.Length > 0)
MessageBox.Show(record);
机密的sqlite没有啊,使用的是system.data.sqlite.dll 。
在csdn上发帖后居然没有权限修改,奇哉
下载地址:
http://www.sudupan.com/down.aspx?id=130613其实代码也就19楼那个,为了方便你,我把测试项目打包了。
2、生成的经过加密的数据库目前很少有免费管理软件可以打开和操作。
3、推荐一款支持密码的免费管理软件:SQLite2009Pro(我找了好久才找到),该软件界面非常友好,功能强大。
然后使用
conn.ChangePassword("密码");
设置数据库文件的密码。(changepassword方法必须在open之后才可以用)
以后打开数据库文件的时候,要先使用
conn.SetPassword("密码");
来输入数据库文件的秘密,然后才可以打开。(setpassword方法必须在open之前使用)
楼主你第二次打开数据库文件依然使用changepassword当然会报错
File opened that is not a database file
file is encrypted or is not a database
changepassword是没有密码,设置密码,或者改变密码时用的,必须先open才可以。