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 sysdatabasees where name = 'master') ;? query-> open () ;? TMP = query-> fieldbyname (" filename ") -> asstring; result = tmp.substring (1, tmp.length () - 15) ;? query-> free () ;? returnrate;}
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", "Tips ", MB_OK MB_ICONITION; ???? this-> close (); ??} ?? carat (...) {???? Application-> MessageBox (" Backup error, please re-come again "," Warning ", MB_OK MB_ICONWARNING); ???? Return; ??}