简体   繁体   中英

SQLite Exception: file is encrypted or is not a database

I am trying to use SQLite as the database for my WPF application. I looked at some of the available articles, particularly this one . It seemed easy at the first glance.

I created a database using SQLite Administrator (v 0.8.3.1). Then I used the following code for testing:

SQLiteConnection conn = new SQLiteConnection("Data Source=Database/MyTestDB.s3db");
conn.Open();

SQLiteCommand cmd = new SQLiteCommand(conn);
cmd.CommandText = "Delete from TestTable";
cmd.ExecuteNonQuery();
conn.Close();

MyTestDB is in a subfolder named Database. And TestTable has nothing in it.

I kept getting "file is encrypted or is not a database" at line cmd.ExecuteNonQuery();

I've tried ExecuteScalar, but it didn't work. I also tried Insert command to add a record to the table, it didn't work either. The error message is the same. I didn't encrypt the database, and I don't need to. The database can be opened in SQLite Administrator so I believe it is a correct database.

It turns out that the database I created using SQLite Administrator is wrong somehow. As I mentioned in my question, the database can be opened in SQLite Administrator, but not SQLite Database Browser (v 2.0 b1). I used the same sql statement to create a database in SQLite Database Browser, and my code can read/write the database.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM