![](/img/trans.png)
[英]Encrypted SQLite database can't be opened with System.Data.SQLite
[英]How to Solve this Error “file is encrypted or is not a database file is encrypted or is not a database” Source=System.Data.SQLite
我的代码在下面
private void FillTable()
{
//string ConnectionString = @"Data Source=MedicineDatabase.db;Version=3;Password=h2ckerinsideh2ckerinsideh2ckerinside;";
using (SQLiteConnection con = new SQLiteConnection(@"Data Source=MedicineDatabase.db;Version=3;Password='abc';"))
{
SQLiteCommand cmd = new SQLiteCommand();
string CommandText = "select * from Medicines";
SQLiteDataAdapter DB = new SQLiteDataAdapter(CommandText, con);
DataSet DS = new DataSet();
DS.Reset();
DB.Fill(DS);
using (DataTable dt = new DataTable())
{
DB.Fill(dt);
MedicineMetroGrid.DataSource = dt;
}
}
}
和
我遇到了这个错误
**
“文件已加密或不是数据库文件已加密或不是数据库”
**除非我的代码看起来很完美,否则会有问题吗? 我使用带C#的sqlite来构建一个简单的程序,我需要加密.db文件。
像这样查看更多详细信息,我从那里复制粘贴的答案,希望对您有所帮助,
当您在连接字符串中指定密码并且数据库已经存在时,SQLite会假定数据库已加密,并将尝试使用所述密码对其进行解密。 如果您尚未在数据库上设置密码,这将导致“文件已加密”错误,因为提供的密码无法用于解密未加密的数据库。
您可以删除数据库,然后SQLite将使用连接字符串中的密码创建一个新的加密数据库。 或者,您可以使用ChangePassword()方法加密现有数据库:
// Opens an unencrypted database
SQLiteConnection cnn = new SQLiteConnection("Data Source=c:\\test.db3");
cnn.Open();
// Encrypts the database. The connection remains valid and usable afterwards.
cnn.ChangePassword("mypassword");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.