Click here to Skip to main content
11,708,312 members (64,524 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET Sqlite
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 18-Aug-12 8:18am
DEB4u594
Comments
Kenneth Haugland at 18-Aug-12 14:31pm
   
Cant you set it password protected? and encrypt the data?
DEB4u at 19-Aug-12 3:44am
   
password protected
Sergey Alexandrovich Kryukov at 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
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

  Permalink  
Comments
DEB4u at 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 at 19-Aug-12 4:33am
   
Usually you open another db without password then copy the data over.
cynik40 at 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("")
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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

To remove the password:
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:
connectionString += "Password=" + thePassword + ";";
  Permalink  
Comments
aruyc at 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 at 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.

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

  Print Answers RSS
0 Maciej Los 220
1 OriginalGriff 183
2 Mika Wendelius 180
3 Sergey Alexandrovich Kryukov 149
4 Peter Leow 130
0 OriginalGriff 9,253
1 Sergey Alexandrovich Kryukov 8,562
2 CPallini 5,189
3 Maciej Los 4,966
4 Mika Wendelius 3,856


Advertise | Privacy | Mobile
Web01 | 2.8.150819.1 | Last Updated 15 Oct 2014
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100