How to backup and restore access database using C#.Net



In the Previous Article i told you How to take database backup using C# .Here i will explain How to restore access database using C#.Net.


In the Previous articles i explained redirect to page according to role while login in asp.nethow to open form on click of the button using c#.nethow to close form on click of the button using C#.nethow to insert record into database from listview control using, how to backup and restore access database using and many more about C#.Net.

Step 1.

Write the below code on click event of the Button. Using Below code we will browse for database which we want to Restore. We will use Copy() function for restoring database. We will pass source and destination path in Copy Function. e.g. Copy(source, destination). And you are Done.

                    OpenFileDialog SaveFD12 = new OpenFileDialog();
                    // SaveFileDialog SaveFD12 = new SaveFileDialog();
                    string FileName = "";
                    SaveFD12.InitialDirectory = "C:";
                    SaveFD12.FileName = "";
                    SaveFD12.Title = "Choose Backup file to Restore ";
                    SaveFD12.DefaultExt = "mdb";
                    SaveFD12.Filter = "Ms-Access Files (*.mdb)|*.mdb|All Files|*.*";
                    //SaveFD1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"; 
                    SaveFD12.FilterIndex = 1;
                    SaveFD12.RestoreDirectory = true;
                    if (SaveFD12.ShowDialog() == DialogResult.OK)
                        FileName = SaveFD12.FileName;
                        string src = FileName;
                        string dst = Application.StartupPath + @"\hotel.mdb";
                        System.IO.File.Copy(src, dst, true);
                        MessageBox.Show("Backup is Restored Successfully !", "Backup Status", MessageBoxButtons.OK, MessageBoxIcon.Information);
                catch (Exception ex)
                    MessageBox.Show("Error while restoring backup!" + ex, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

Give your Valuable Comments.
comments powered by Disqus
Follow me on twitter
About Me
Harpreet Singh
I began programming with C++ when i was 17. Then at the middle of my study .NET came. Then I began to read C# and VB.NET. By the time i learnt SQL and ASP.NET, and developed some websites such as news portals that are active now. Currently i am running my own Software company.
More Articles