Click here to Skip to main content
15,892,674 members

Comments by aruyc (Top 2 by date)

aruyc 3-Apr-15 8:07am View    
Found solution of my question. when you need to open connection again just initialize connection object with connection string having password. working now.
aruyc 31-Mar-15 2:25am View    
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?