简体   繁体   English

在SQLite数据库中出现错误“文件已加密还是未加密数据库”?

[英]Getting error “file is encrypted or not a database” in SQLite DataBase?

I am using SQLite Database in C# and trying to encrypt it but when I am setting the Password in Connection.SetPassword it is giving me above error. 我在C#中使用SQLite数据库并尝试对其进行加密,但是当我在Connection.SetPassword中设置密码时,它给了我上面的错误。

connection.SetPassword("12345");
trans=connection.BeginTransaction();

I am getting the error on BeginTransaction() method. 我在BeginTransaction()方法上遇到错误。 Is there any way to resolve it and set password successfully to SQLite Database. 有什么方法可以解决该问题并成功将密码设置为SQLite数据库。

You need to open the connection after setting the password. 设置密码后,您需要打开连接。

Follow this example: 请遵循以下示例:

 connection = new SQLiteConnection(connString);
 //Set the password
 connection.SetPassword("12345");
 //Open the connection
 connection.Open();
 connection.Close();

If you want to connect to the same DB and remove the password then do as following: 如果要连接到相同的数据库并删除密码,请执行以下操作:

 connection = new SQLiteConnection(connString);
 connection.SetPassword("12345");
 connection.Open();
 connection.ChangePassword("");
 connection.Close();

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

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