C++Builder中,sqlserver在客户端调用存储过程向服务器端备份数据库
2007-11-11 08:48:24 来源:WEB开发网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(WINDOWS平台上强大的数据库平台).
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;
}
- ››sqlserver 每30分自动生成一次
- ››sqlserver安装和简单的使用
- ››SqlServer触发器、存储过程和函数
- ››SQLServer建立交叉表查询
- ››SqlServer强制断开数据库连接的方法
- ››SQLServer 2005 海量数据解决方案
- ››SQLServer 2008数据库查看死锁、堵塞的SQL语句
- ››SqlServer 插入多条数据
- ››SQLServer 2008 R2导出的SQL文件中没有数据
- ››SQLSERVER通过游标查询两个数据表共有字段名组合成...
- ››sqlserver2008实现拼音首字母和随机n位数的生成
- ››SQLServer与Java数据类型对应表
更多精彩
赞助商链接