C++ Builder中,sql server在客户端调用存储过程向服务器端备份数据库
2024-08-31 00:48:28
供稿:网友
1.create a backup database stored procedure in master database.
create procedure backupdb
@database varchar(10),
@directory varchar(100)
as
backup database @database
to [email protected]
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;
}
本文来源于网页设计爱好者web开发社区http://www.html.org.cn收集整理,欢迎访问。