How to get result from SQL BACKUP command into Delphi program?

The output of sql commands, visible to users who interactively run SQL commands from SQL Server Management, is different from the output returned from an ADO command or an ADO query object.

USE [DBNAME] 
BACKUP DATABASE [DBNAME] TO 
 DISK = 'C:\SqlBackup\Backup.mdf'

A successful completion result is as follows:

Processed 465200 pages for database 'DBNAME', file 'filename' on file 2.
Processed 2 pages for database 'DBNAME', file 'filename_log' on file 2.
BACKUP DATABASE successfully processed 465202 pages in 90.595 seconds (40.116 MB/sec).

When I execute either TADOCommand or TADOQuery with CommandText or SQL as above, I do not get this output. How to read this "secondary result" from an SQL command? I hope that perhaps through some raw ADO operations, I could execute the command and get the information above for success, as well as any errors while performing Sql backup.

. , , , Delphi TADOCommand TADOConnection:

  • TADOCommand TADOConnection.
  • .
  • .

, , , " dbname" , , "use dbname", , . , ADO, , , . , , Com Anyways VCL . , - , , "SQL Backup Delphi" .

+5
1

. D7 MSSQL2000. Memo1 :

29 percent backed up.
58 percent backed up.
82 percent backed up.
98 percent backed up.
Processed 408 pages for database 'NorthWind', file 'Northwind' on file 1.
100 percent backed up.
Processed 1 pages for database 'NorthWind', file 'Northwind_log' on file 1.
BACKUP DATABASE successfully processed 409 pages in 0.124 seconds (26.962 MB/sec).

, , , WHILE .

uses AdoInt,ComObj;
.....

procedure TForm1.Button1Click(Sender: TObject);
var cmd  : _Command;
    Conn : _Connection;
    RA   : OleVariant;
    rs   :_RecordSet;
    n    : Integer;
begin
  Memo1.Clear;

  Conn := CreateComObject(CLASS_Connection) as _Connection;
  Conn.ConnectionString := 'Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=NorthWind;Data Source=SQL_Server';
  Conn.Open(Conn.ConnectionString,'','',Integer(adConnectUnspecified));

  cmd := CreateComObject(CLASS_Command) as _Command;
  cmd.CommandType := adCmdText;
  cmd.Set_ActiveConnection(Conn);
  cmd.CommandText := 'BACKUP DATABASE [NorthWind] TO  DISK = N''c:\sql_backup\NorthWind'' WITH  INIT ,  NOUNLOAD ,  NAME = N''NortWind backup'',  NOSKIP ,  STATS = 10,  NOFORMAT;';
  rs:=cmd.Execute(RA,0,Integer(adCmdText));

  while (rs<>nil) do
  begin
   for n:=0 to(Conn.Errors.Count-1)do begin
    Memo1.Lines.Add(Conn.Errors.Item[n].Description);
   end;
   rs:=rs.NextRecordset(RA);
  end;

  cmd.Set_ActiveConnection(nil);
  Conn.Close;
  cmd  := nil;
  Conn := nil;
end;

() BACKUP.

+5

All Articles