I am developing a C# application that uses a Microsoft mdb Database "OLEDB.12.0" for storing records, all works just fine. However I would like to be able to make a backup of the Database when a user clicks on a button.
At the moment I am using the following code that works when running it through MS Studio 2015, but fails after it is installed.
string DBFile = "Database.mdb" as string;
//Set Database Filename As Today's Date For Backup And Replace Unwanted Characters
string ThisDate = DateTime.Now.ToString("M/d/yyyy") as string;
char[] separators = new char[] { ' ', '/', ',', '\r', '\t', '\n' };
string[] temp = ThisDate.Split(separators, StringSplitOptions.RemoveEmptyEntries);
ThisDate = String.Join("_", temp);
//Open The Save Dialog
SaveFileDialog openFileDialogDB = new SaveFileDialog();
openFileDialogDB.InitialDirectory = Application.ExecutablePath.ToString();
openFileDialogDB.Filter = "mdb files (*.mdb)|*.mdb|All files (*.*)|*.*";
openFileDialogDB.FilterIndex = 1;
openFileDialogDB.RestoreDirectory = true;
openFileDialogDB.FileName = ThisDate;
if (openFileDialogDB.ShowDialog() == DialogResult.OK)
{
//Save Database Backup
File.Copy(DBFile, openFileDialogDB.FileName, true);
}
The error I get after installing using Install Shield is.
System.IO.FileNotFoundException: Could not find file 'Database.mdb'. File name: 'Database.mdb'
And after installing using One click install I get.
System.IO.FileNotFoundException: Could not find file 'C:\Users\Username\AppData\Local\Apps\2.0\X27G5OGV.1A8\X58VRM4Y.HGD\lght..tion_0000000000000000_0001.0000_f0c86b36a0494a4c\Database.mdb'
So my question is how do I make a backup of the Database after the application is installed.
The odd part is, if I configure Install Shield to run the application after setup completes and then do a DB backup it works fine. However if I exit and restart the application it again fails