简体   繁体   中英

How to Solve this Error “file is encrypted or is not a database file is encrypted or is not a database” Source=System.Data.SQLite

My Code is Below

private void FillTable()
    {

        //string ConnectionString = @"Data Source=MedicineDatabase.db;Version=3;Password=h2ckerinsideh2ckerinsideh2ckerinside;";
        using (SQLiteConnection con = new SQLiteConnection(@"Data Source=MedicineDatabase.db;Version=3;Password='abc';"))
        {
            SQLiteCommand cmd = new SQLiteCommand();
            string CommandText = "select * from  Medicines";
            SQLiteDataAdapter DB = new SQLiteDataAdapter(CommandText, con);
            DataSet DS = new DataSet();
            DS.Reset();
            DB.Fill(DS);

            using (DataTable dt = new DataTable())
            {
                DB.Fill(dt);
                MedicineMetroGrid.DataSource = dt;
            }
        }
    }

and

i Got this Error

**

"file is encrypted or is not a database file is encrypted or is not a database"

** unless that my code looks perfect is there a problem ? i am using sqlite with c# to build a simple program i needs to encrypt .db file.

Go to this like for more details I copy pasted answer from there, hope it will help,

When you specify a password in the connection string, and the database already exists, SQLite assumes the database is encrypted and will try to decrypt it with said password. If you haven't set a password on the database yet, this will result in the "file is encrypted" error, because the supplied password can't be used to decrypt an unencrypted database.

You can either delete the database, and SQLite will create a new encrypted database using the password in the connection string. Or, you can encrypt your existing database using the ChangePassword() method:

// Opens an unencrypted database    
SQLiteConnection cnn = new SQLiteConnection("Data Source=c:\\test.db3");    
cnn.Open();    

// Encrypts the database. The connection remains valid and usable afterwards.    
cnn.ChangePassword("mypassword");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM