Click here to Skip to main content
15,881,898 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
Hi,

I've developed a windows application which runs on a sqlite database. I'm packaging that .db file with installer. But i want that this .db file should not be opened by any sqlite editor like SqliteAdmin etc.. ANy idea how to do this??


Thank you
Posted
Updated 7-Jul-22 9:15am
Comments
Kenneth Haugland 18-Aug-12 14:31pm    
Cant you set it password protected? and encrypt the data?
DEB4u 19-Aug-12 3:44am    
password protected
Sergey Alexandrovich Kryukov 18-Aug-12 14:33pm    
Does it mean that you are not using it as a server? You need to explain who are you protecting it from. If there is a key to decrypt it to serve data, anyone who can get the key can decrypt it too. So, any realistic scenario?
--SA

 
Share this answer
 
Comments
DEB4u 19-Aug-12 3:47am    
it worked for setting the database password :
conn = New SQLiteConnection()
conn.ChangePassword("password")
..

It sets the password.. but how to remove the password?
Mehdi Gholam 19-Aug-12 4:33am    
Usually you open another db without password then copy the data over.
[no name] 19-Nov-13 10:36am    
"It sets the password.. but how to remove the password?"

conn = New SQLiteConnection() conn.ChangePassword("sPassword")

(Spassword = string.empty)

or conn = New SQLiteConnection() conn.ChangePassword("")
To set the password:
C#
public static void SetPassword ()
{
    var con = new SQLiteConnection(connectionString);
    con.Open();
    con.ChangePassword(PASSWORD);
    con.Close();
}


To remove the password:
C#
public static void ReSetPassword()
{
    var con = new SQLiteConnection(connectionString);
    con.Open();
    con.ChangePassword("");
    con.Close();
}


To open the encrypted database programmatically, append the password to the regular connection string:
C#
connectionString += "Password=" + thePassword + ";";
 
Share this answer
 
Comments
aruyc 31-Mar-15 2:25am    
Getting error while querying password protected database "file is encrypted or is not a database" even though password in connection string is right.

code:
public DataFile()
{
string dbPath = Environment.CurrentDirectory + "\\DataBase\\mydb1.sqlite";
string conn = @"Data Source=" + dbPath + ";";
sqlcon = new SQLiteConnection(conn);

sqlcon.Open();
sqlcon.ChangePassword("mydb"); //setting password here
sqlcon.Close();

conn = @"Data Source=" + dbPath + ";Password=mydb;";
sqlcon = new SQLiteConnection(conn);
}

internal DataSet SQLiteSelect(string TableName)
{
SQLiteCommand cmd = new SQLiteCommand(sqlcon);
DataSet ds = new DataSet(TableName);
sqlcon.Open();
cmd.CommandText = "select * from " + TableName;
SQLiteDataAdapter datadapter = new SQLiteDataAdapter(cmd);
try
{
datadapter.Fill(ds, TableName);
}
catch (Exception ex)
{
MessageBox.Show("Error: " + ex.Message);
}
finally
{
cmd.Dispose();
sqlcon.Close();
}
return ds;
}

I am getting error at
datadapter.Fill(ds, TableName);

what i am doing wrong?
aruyc 3-Apr-15 8:07am    
Found solution of my question. when you need to open connection again just initialize connection object with connection string having password. working now.
sandip.chaudhari90 25-Sep-15 11:06am    
Can u please explain in details i have same issue
To password protect and to encrypt an sqlite database, using military grade encryption, you will need to buy SQLite Encryption Extension[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900