简体   繁体   中英

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.

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

I am getting the error on BeginTransaction() method. Is there any way to resolve it and set password successfully to SQLite Database.

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();

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