![](/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.