如何恢复访问数据库?

时间:2015-07-24 11:19:23

标签: c# winforms ms-access-2007

string dbFileName = "abc.mdb";
string CurrentDatabasePath = Path.Combine(@"F:\New Folder\Database\abc.mdb");
string destFileName = dbFileName;

FolderBrowserDialog fbd = new FolderBrowserDialog();

if (fbd.ShowDialog() == DialogResult.OK)
{
    string PathtobackUp = fbd.SelectedPath.ToString();
    destFileName = Path.Combine(PathtobackUp, destFileName);

    File.Copy(CurrentDatabasePath, destFileName, true);

    MessageBox.Show("successful Backup! ");
}

这是用于备份数据库。恢复数据库的方法是什么?

1 个答案:

答案 0 :(得分:0)

从某个位置恢复数据库:

string PathToRestoreDB =  Environment.CurrentDirectory + @"\dbname.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 Database From Backup Folder
File.Copy(Filetorestore, PathToRestoreDB,true);