In C + + builder, SQL Server backs up the database to the server side at the client call stored procedure

Source: Internet
Author: User
Tags query client backup
c++|server| backup | stored Procedure | server | client | data | database
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 ("Backup Complete", "hint", mb_ok+mb_iconinformation);
This->close ();
}
catch (...) {
Application->messagebox ("Backup error, please come back again", "warning", mb_ok+mb_iconwarning);
Return
}


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.