简体   繁体   English

SQLite异常:文件已加密或不是数据库

[英]SQLite Exception: file is encrypted or is not a database

I am trying to use SQLite as the database for my WPF application. 我正在尝试将SQLite用作WPF应用程序的数据库。 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). 我使用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. MyTestDB在名为Database的子文件夹中。 And TestTable has nothing in it. 而且TestTable中没有任何内容。

I kept getting "file is encrypted or is not a database" at line cmd.ExecuteNonQuery(); 我在cmd.ExecuteNonQuery();行中不断收到“文件已加密或不是数据库”的信息。

I've tried ExecuteScalar, but it didn't work. 我已经尝试了ExecuteScalar,但是没有用。 I also tried Insert command to add a record to the table, it didn't work either. 我还尝试了Insert命令向表中添加一条记录,但也没有用。 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. 可以在SQLite Administrator中打开数据库,因此我认为它是正确的数据库。

It turns out that the database I created using SQLite Administrator is wrong somehow. 事实证明,我使用SQLite Administrator创建的数据库在某种程度上是错误的。 As I mentioned in my question, the database can be opened in SQLite Administrator, but not SQLite Database Browser (v 2.0 b1). 正如我在问题中提到的,可以在SQLite Administrator中打开数据库,但不能在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. 我使用相同的sql语句在SQLite数据库浏览器中创建数据库,并且我的代码可以读取/写入数据库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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