程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> SqlServer數據庫 >> 關於SqlServer >> C++Builder中,sqlserver在客戶端調用存儲過程向服務器端備份數據庫

C++Builder中,sqlserver在客戶端調用存儲過程向服務器端備份數據庫

編輯:關於SqlServer

1.Create a backup database stored procedure in master database.

CREATE PROCEDURE backupdb
@database varchar(10),
@directory varchar(100)
AS
backup database @database
to disk=@directory

2.Get path of SQL Server.

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;
}

3.Call the backup database stored procedure.

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->ProcedureName="backupdb;1";
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;
}

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved