Backup and restore of a database
Hi,
I am using MS-Access as my database. I want to create a form which will take the backup of the database and when i will install the application on some other place, and try to restore the database it will restore it on that system. Please help. Tell me for MS-Access please.
Kirtan PatelPosted Sep 16, 2009, 10:36 AM
Hi,
Vandana
Here is Solution to Your Problem
Back Up Process
private void btnBackUp_Click(object sender, EventArgs e)
{
string CurrentDatabasePath = Environment.CurrentDirectory + @"\Database3.accdb";
FolderBrowserDialog fbd = new FolderBrowserDialog();
if (fbd.ShowDialog() == DialogResult.OK)
{
string PathtobackUp = fbd.SelectedPath.ToString();
File.Copy(CurrentDatabasePath,PathtobackUp+@"\BackUp.accdb",true);
MessageBox.Show("Back Up SuccessFull! ");
}
}
//Restore Process
private void button2_Click(object sender, EventArgs e)
{
string PathToRestoreDB = Environment.CurrentDirectory + @"\Database3.accdb";
OpenFileDialog ofd = new OpenFileDialog();
if (ofd.ShowDialog() == DialogResult.OK)
{
string Filetorestore = ofd.FileName;
// Rename Current Database to .Bak
File.Move(PathToRestoreDB, PathToRestoreDB + ".bak");
//Restore the Databse From Backup Folder
File.Copy(Filetorestore, PathToRestoreDB,true);
}
}