RICHARD KNOX

RICHARD KNOX

  • 1.7k
  • 86
  • 2.6k

SQLite - Backing up a database programmically C#

May 10 2024 7:00 PM

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();

}

 


Answers (5)