Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi friends,
In my project am using access database in that I want to make backup and restore functions for some criteria.Suggest some ideas about access DB backup and restore?
Posted
Comments
BulletVictim 5-Nov-13 1:19am    
I used the following with my access database project. This just makes a copy of the database in the desired location and the on the restore it overwrites the current database being used.
private void btnBackup_Click(object sender, EventArgs e)
{
try
{
string CurrentDatabasepath = Environment.CurrentDirectory + @"\Database.accdb";
FolderBrowserDialog fbd = new FolderBrowserDialog();
if (fbd.ShowDialog() == DialogResult.OK)
{
string PathToBackup = fbd.SelectedPath.ToString();
File.Copy(CurrentDatabasepath, PathToBackup + @"\Database.accdb", true);
MessageBox.Show("Backup Successfull");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}

private void btnRestore_Click(object sender, EventArgs e)
{
try
{
string PathToRestoreDB = Environment.CurrentDirectory + @"\Database.accdb";
OpenFileDialog ofd = new OpenFileDialog();
if (ofd.ShowDialog() == DialogResult.OK)
{
string FileToRestore = ofd.FileName;
File.Move(PathToRestoreDB, PathToRestoreDB);
File.Copy(FileToRestore, PathToRestoreDB, true);
MessageBox.Show("Database Has Been Restored");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}

I hope this helps point you in a direction. If you find a better method than this please let me know?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900