爱心技术专栏专题

C++Builder中,sqlserver在客户端调用存储过程向服务器端备份数据

摘录:MSSQL Server教程 来源:MSSQL Server教程 加入时间:2007年03月25日
摘要:
C++Builder中,sqlserver在客户端调用存储过程向服务器端备份数据

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

CREATE PROCEDURE backupdb
  @database varchar(10),
  @directory varchar(100)
AS
  backup da…

转载:转载请保留本信息,本文来自
http://www.51dibs.com
/html/2006/article/info22/a_c4167001e242727c.htm

C++Builder中,sqlserver在客户端调用存储过程向服务器端备份数据

站点:爱心种子小博士 关键字:C++Builder中,sqlserve

   
C++Builder中,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;
   }


客户服务中心信箱:[email protected] [email protected] 网站地图

声明

合作伙伴: