I created a piece of code to backup a SQLite db, but I keep getting an error and I can't figure it out. Any assistacne would be greatfully accepted.

private void btnExport_Click(object sender, EventArgs e)
{
AC.cmd.Parameters.Clear();
var filePath = Application.StartupPath + "\\" + "Backup";
AC.OpenConnection();
var query = String.Format("BACKUP DATABASE [{0}] TO DISK='{1}'", AC.dbName, filePath);
AC.cmd.CommandType = CommandType.Text;
AC.cmd.CommandText = query;
AC.cmd.ExecuteNonQuery();
AC.CloseConnection();
}
Jaimin ShethiyaPosted May 12, 2024, 6:57 AM
Hello,
Try below code.
string backupFilePath = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(
System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase), @"\backup\backup.db");
string OriginalFile =@"D:\sqlite.db";
File.Copy(OriginalFile, backupFilePath, true);
Thanks
RICHARD KNOXPosted May 11, 2024, 11:37 PM
Sam,
I removed the brackets and it still doesnt accomplish anything.
RICHARD KNOXPosted May 11, 2024, 11:36 PM
Jaimin,
The code works, but inside the backup file there is no tables or data. Its just a shell.
Jaimin ShethiyaPosted May 11, 2024, 10:23 AM
Hello,
Try below code.
and also please refer for more info to below links.
https://blog.devgenius.io/backup-and-restore-sqlite-database-db-using-c-net-bbe25a428cdf
https://stackoverflow.com/questions/34760033/how-to-take-sqlite-database-backup-using-c-sharp-or-sqlite-query
Thanks
Sam HobbsPosted May 10, 2024, 8:12 PM
Are you sure you need the square brackets? Try:
Instead of: