C++Builder中,sqlserver在客户端调用存储历程向服务器端备份数[MSSQL防范]
本文“C++Builder中,sqlserver在客户端调用存储历程向服务器端备份数[MSSQL防范]”是由七道奇为您精心收集,来源于网络转载,文章版权归文章作者所有,本站不对其观点以及内容做任何评价,请读者自行判断,以下是其具体内容:
1.Create a backup database stored procedure in master database.iTbulo .comYLZoM
CREATE PROCEDURE backupdb
@database varchar(10),
@Directory varchar(100)
AS
backup database @database
to disk=@directoryiTbulo .comYLZoM
2.Get path of sql server.iTbulo .comYLZoM
AnsiString __fastcall TFrmDM::GetSqlServerPath(){
AnsiString result,tmp;
TADOQuery *Query=new TADOQuery(this);
Query->Connection=ADOConnection_Master;
Query->Close();
Query->SQL->Clear();
Query->SQL->Add("select filename from sysdatabases where name='master'");
Query->Open();
tmp=Query->FieldByName("filename")->AsString;
result=tmp.SubString(1,tmp.Length()-15);
Query->Free();
return result;
}iTbulo .comYLZoM
3.Call the backup database stored procedure.iTbulo .comYLZoM
d=FormatDateTime("yyyy-mm-dd hh-mm-ss",FrmDM->GetServerTime());
try{
path=FrmDM->GetSqlServerPath()+"backup\\";
FrmDM->ADostoredProc1->Close();
FrmDM->ADOStoredProc1->Connection=FrmDM->ADOConnection_Master;
FrmDM->ADOStoredProc1->Prepared=true;
FrmDM->ADOStoredProc1->Procedure;
FrmDM->ADOStoredProc1->Parameters->ParamByName("@database")->Value = "db_name_to_backup";
FrmDM->ADOStoredProc1->Parameters->ParamByName("@directory")->Value =path+"db_name_to_backup"+d;
FrmDM->ADOStoredProc1->ExecProc();
Application->MessageBox("备份完成","提醒",MB_OK+MB_ICONINFORMATION);
this->Close();
}
catch(...){
Application->MessageBox("备份出错,请重新再来","告诫",MB_OK+MB_ICONWARNING);
return;
}iTbulo .comYLZoM
本文地址: | 与您的QQ/BBS好友分享! |