Sunday, 13 January 2013 14:56

how to backup database file of your application

Written by 
Rate this item
(0 votes)

you should backup your database file of your
windows software.there are many reasons why you
will backup your database file.i will not write
details about that.i showing here how to
backup your database file for safety of your
database -

the following button click method does the backup -

private void buttonSave_Click(object sender, EventArgs e)
//first set your application's database directory
//and the target directory where backup will be saved

String sCurrentPath;
if (ApplicationDeployment.IsNetworkDeployed)
else sCurrentPath=Application.StartupPath;

String backupFilePath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);

//the following way backup is done
string fileName = "database.mdb";
string sourcePath = currentPath;
string targetPath = backupFilePath;
string sourceFile = System.IO.Path.Combine(sourcePath, fileName);
string destFile = System.IO.Path.Combine(targetPath, fileName);
if (!System.IO.Directory.Exists(targetPath))
System.IO.File.Copy(sourceFile, destFile, true);
bSaved = true;
catch (Exception ex)
MessageBox.Show("Error during backup", "application Database Error");

Read 2675 times
Super User

Email This email address is being protected from spambots. You need JavaScript enabled to view it.

Latest discussions

  • No posts to display.