Backup and Restore in Delphi with Sql Server how to do?

0

Hello, I'd like to know how I can do Backup and Restore to integrate with my system. I have a ready code but it is for firebird I believe it will not serve for Sql Server. I have read on some topics that there are no components for Backup and Restore with Sql Server in Delphi, the only ways to do it would be via line of code, in another article I found something about doing a procedure in the database and calling it in Delphi . My big problem is that I have never done a procedure in the database and neither is my database very much. Finally I would like to know if you can help me develop a Backup and Restore for Delphi system using Sql Server 2012

    
asked by anonymous 18.04.2017 / 16:39

1 answer

1
procedure TBackupRestore.BtnBackUpClick(Sender: TObject);
var
  ADOCommand : TADOCommand;
  CLIENTE : String;
begin

  CLIENTE := 'teste';

  ADOCommand := TADOCommand.Create(nil); //Cria o objeto de comando para executar a rotina de backup do SQL SERVER 2000
  with ADOCommand do begin
    //ADOCommand.Name := 'ADOGeraBackup'; //Nome do objeto
    ADOCommand.ConnectionString := ADOConnection1.ConnectionString; //Cria a conexão com o Provider do SQL Server
    //ADOCommand.CommandType := cmdText; //Define como command Text para execução de linhas de comando
    ADOCommand.CommandText := 'BACKUP DATABASE '+CLIENTE+' TO DISK =''c:\SQLBackUp\sql.bak''';
    ADOCommand.Execute; //Executa a linha de comando
  end;

end;

Restore will look like this, however you will have to work a code to run first on a test table, it will work, but if you break your head I think you can do it!

    
19.04.2017 / 15:20