I use MS Access database and I want to create a simple backup system, but I have not idea how to create it. I tried with copy paste on the database but I got error because my database is being used by my application... I also tried to disconnect the connection with the base, but i got the same error again...
My problem is in the replace the backup...
// New Open File Dialot
OpenFileDialog ofd = new OpenFileDialog();
ofd.Title = "Враќање бекап";
ofd.Filter = "MS Access Database (*.mdb)|*.mdb";
// Locate the Path of the my application
System.Reflection.Assembly asb = System.Reflection.Assembly.GetEntryAssembly();
string directoryPath = System.IO.Path.GetDirectoryName(asb.Location);
string myFileName = "";
string myPath = "";
if (ofd.ShowDialog() == DialogResult.OK)
{
// Get the filename of the selected .mdb file...
myFileName = System.IO.Path.GetFileName(ofd.FileName);
// Get the path of the selectet .mdb file...
myPath = System.IO.Path.GetDirectoryName(ofd.FileName);
// if .mdb alredy exists
if (File.Exists(@"" + directoryPath + "/myNotebook.mdb"))
{
DialogResult dr = MessageBox.Show("bla bla", "Warning",
MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2);
if (dr == DialogResult.Yes)
{
try
{
Form1 frmMainForm = new Form1();
// Closing the connection with the database
frmMainForm.database.Close();
// Try delete alredy exists database
File.Delete(directoryPath + "//myNotebook.mdb");
// Replace the new database...
File.Copy(@"" + myPath + "/" + myFileName, @"" + directoryPath + "/myNotebook.mdb");
}
.....
Anyone help me ?
Thanks...