备份还原SQL数据库
//数据备份只能备份本地数据库服务器
String filename="";
if(sd->Execute())
{
filename=sd->FileName;
}
else
{
return;
}
Screen->Cursor=crHourGlass;
TADOQuery *qrbk=new TADOQuery(this);
qrbk->Connection=dm->adocon;
qrbk->SQL->Text=String("backup database erp to disk='") + filename+ String("'");
try
{
qrbk->ExecSQL();
}
catch(...)
{
delete qrbk;
qrbk=NULL;
Screen->Cursor=crDefault;
ShowMessage(String("备份失败!\n请选择不同文件名!\n原文件名为:")+filename);
return;
}
delete qrbk;
qrbk=NULL;
Screen->Cursor=crDefault;
ShowMessage(String("备份成功!\n文件名为:")+filename);
//数据恢复
String filename="";
if(od->Execute())
{
filename=od->FileName;
}
else
{
return;
}
Screen->Cursor=crHourGlass;
TADOQuery *qrbk=new TADOQuery(this);
qrbk->Connection=dm->adocon;
qrbk->SQL->Text=String("use tempdb \n restore database erp from disk='") + filename+ String("' \n use erp\n");
try
{
qrbk->ExecSQL();
}
catch(...)
{
delete qrbk;
qrbk=NULL;
Screen->Cursor=crDefault;
ShowMessage(String("还原失败!\n请确认没有其他程序访问该数据库!\n并且还原文件完好无损!还原文件名为:")+filename);
return;
}
delete qrbk;
qrbk=NULL;
Screen->Cursor=crDefault;
ShowMessage(String("还原成功!\n文件名为:")+filename);