Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Friday, April 13, 2018 9:37 AM
Hi,
how can I set a password to my database. So nobody can use my file.db.
Till now I was trying this ...
string conString = @"Data Source=file.db;Version=3;";
SQLiteConnection conn = new SQLiteConnection(conString);
conn.SetPassword("password");
conn.Open();
but it show me an error message ...
File openedthat is not a database file
file is encrypted or is not a database
What is the problem? Thank you.
All replies (8)
Friday, April 13, 2018 10:20 AM
Your connectionstring misses a folder assignment
Success
Cor
Friday, April 13, 2018 11:00 AM
I dont understand this. I use this connection string and it works, but when I wanted to set a password to database, it showed me that error message.
Friday, April 13, 2018 11:19 AM
The problem seems to be, that you cannot encrypt a SQLite database that already exists. If you try you'll get those error messages. To circumvent that you'll need to create a new database, encrypt it and then fill it with your data. It's a known problem, take a look at this StackOverflow thread: sqlite-unable-to-open-database-file-is-encrypted-or-is-not-a-database .
wizend
Friday, April 13, 2018 11:29 AM
Hello!
Can't reproduce it.. Did you try to add "Password=password"
to the connection string?
string conString = @"Data Source=file.db;Version=3;Password=password";
SQLiteConnection conn = new SQLiteConnection(conString);
conn.Open();
Monday, April 16, 2018 7:24 AM
Hi friends,
in DB Browser for SQLite I created a new database and set Encryption. Then I opened it in SQLiteStudio and copied table users (with usernames and passwords). Now I am trying to connect in my C# WPF program to a database. But it shows an error. My connection string looks like this :
string conString = @"Data Source=database.db;Version=3;";
using (SQLiteConnection con = new SQLiteConnection(conString))
{
con.Open();
using (SQLiteCommand cmd = new SQLiteCommand("SELECT * FROM users WHERE username=@username", con))
{
...
{
an error ...
File opened that is not a database file
file is encrypted or is not a database.
I know it is encrypted. But I set a password to connection string. What is wrong? Thank you for answers.
Monday, April 16, 2018 7:48 AM
I tried to set encryption via d browser for sqlite
Monday, April 16, 2018 5:18 PM
This is a duplicate to your older thread How to set password to database? You've got some answers there, esp. that your's is not the correct way to create a encrypted SQLite database. Take a look at the StackOverflow link quoted there.
Please, avoid duplicating threads.
wizend
Tuesday, April 17, 2018 5:42 AM
Hi TakeshiKitano,
It there any update, do you resolve the issue. In addition, you could try the following steps.
You could password protect SQLite3 DB. For the first time before doing any operations, set password as follows.
SQLiteConnection conn = new SQLiteConnection("Data Source=file.db;Version=3;");
conn.SetPassword("password");
conn.open();
then next time you can access it like
conn = new SQLiteConnection("Data Source=file.db;Version=3;");
conn.Open();
This wont allow any GUI editor to view your data. Some editors can decrypt the DB if you provide the password. The algorithm used is RSA.
Later if you wish to change the password, use
conn.ChangePassword("new_password");
To reset or remove password, use
conn.ChangePassword(String.Empty);
Best regards,
Zhanglong
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact [email protected].