论坛交流
首页办公自动化| 网页制作| 平面设计| 动画制作| 数据库开发| 程序设计| 全部视频教程
应用视频: Windows | Word2007 | Excel2007 | PowerPoint2007 | Dreamweaver 8 | Fireworks 8 | Flash 8 | Photoshop cs | CorelDraw 12
编程视频: C语言视频教程 | HTML | Div+Css布局 | Javascript | Access数据库 | Asp | Sql Server数据库Asp.net  | Flash AS
当前位置 > 文字教程 > Sql Server教程
Tag:注入,存储过程,分页,安全,优化,加密,索引,日志,压缩,base64,函数,内存,PDF,迁移,结构,破解,编译,配置,进程,分词,触发器,socket,安装,sqlserver2000,sqlserver2005,sqlserver2008,视频教程

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

文章类别:Sql Server | 发表日期:2008-10-5 21:36:25

1.Create a backup database stored procedure in master database.chi na it p owe r .comYLZoM

CREATE PROCEDURE backupdb
  @database varchar(10),
  @directory varchar(100)
AS
  backup database @database
  to disk=@directorychi na it p owe r .comYLZoM

2.Get path of SQL Server.chi na it p owe r .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;
}chi na it p owe r .comYLZoM

3.Call the backup database stored procedure.chi na it p owe r .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->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;
   }chi na it p owe r .comYLZoM

视频教程列表
文章教程搜索
 
Sql Server推荐教程
Sql Server热门教程
看全部视频教程
购买方式/价格
购买视频教程: 咨询客服
tel:15972130058