Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to connect to sqlite database with password

Tags:

c#

sqlite

navicat

I have a sqlite database and I want to connect from my C# program using a password for the database. I am using Navicat and I set encrypt database file with password "test" and then by code my connection string is:

_connection = new SQLiteConnection("Data Source=MedExpress.db;Version=3;Password=\"test\";");

or

_connection = new SQLiteConnection("Data Source=MedExpress.db;Version=3;Password=test;");

But this does not work.

The error is: File opened that is not a database file file is encrypted or is not a database

I can connect to the database without a password like this:

_connection = new SQLiteConnection("Data Source=MedExpress.db;Version=3;");

My question is how can I set a password to a sqlite database and connect from C# program using System.Data.SQLite

like image 308
ddarellis Avatar asked Mar 06 '12 15:03

ddarellis


People also ask

Can I put password on SQLite database?

The base SQLite engine doesn't have any password/encryption options. You have to either use the paid SEE option for encryption, or some third party solution.

How can I open a password protected DB file?

Right-click on your db file in its folder and select "open with..." then select the exe for SQLite2009 Pro, or drag the file onto the exe (assuming you're on Windows), or pass the file path to the exe via the cmd line.

Does SQLite have username and password?

By default, a SQLite database does not require user authentication (no-authentication-required database). After you created a user, the database will be marked as requiring authentication (authentication- required database). Then, user need to provide username and password when connecting to the database file.


1 Answers

This is the connection string with password

Data Source=filename;Version=3;Password=myPassword;

As you stated that you use navicat to set the sqlite encryption. Encryption means that you've encrypted the database it's different from setting a password to a database..

in setting a password to a database try this code..

//create file 
SQLite.SQLiteConnection.CreateFile("c:\\mydatabase file.db3")
Dim cn As New SQLite.SQLiteConnection
//set password
cn.ChangePassword("paxword")
//remove password
cn.ChangePassword("")

Remove the encryption first ..

like image 122
Prince Jea Avatar answered Sep 18 '22 23:09

Prince Jea