Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8390465
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:59:40+00:00 2026-06-09T18:59:40+00:00

The output of sql commands that is visible to users who interactively run SQL

  • 0

The output of sql commands that is visible to users who interactively run SQL commands from SQL Server Management studio, is different than the output you get back from executing an ADO command or ADO query object.

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

The successful completion output is like this:

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 a TADOCommand or TADOQuery with the CommandText or SQL set as above, I do not get any such output. How do I read this “secondary output” from the execution of an SQL command? I’m hoping that perhaps via some raw ADO operations I might be able to execute a command and get back the information above, for success, as well as any errors in performing an Sql backup.

Update: The answer below works better for me than my naive attempt, which did not work, using plain Delphi TADOCommand and TADOConnection classes:

  • create TADOCommand and TADOConnection.
  • execute command.
  • get info-messages back.

The problem I experienced in my own coding attempts, is that my first command is “use dbname” and the only recordset I traversed in my code, was the results of the “use dbname” command, not the second command I was executing. The accepted answer below traverses all recordsets that come back from executing the ADO command, and thus it works much better. Since I’m doing all this in a background thread, I actually think it’s better to create the raw Com Objects anyways, and avoid any VCL entanglement in my thread. The code below could be a nice component if anybody is interested, let me know and I might make an open source “SQL Backup for Delphi” component.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T18:59:41+00:00Added an answer on June 9, 2026 at 6:59 pm

    Here is an example. I’ve tested it with D7 and MSSQL2000. And it adds to Memo1 all messages from server:

    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).
    

    Also if it takes a long time consider to implement a WHILE loop not in the main thread.

    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;
    

    I’ve found this thread (Russian) for stored procedure and correct it for BACKUP command.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a SQL Server 2005 output like this: Date | Result | Sum
Describe the output of the following SQL query: select custId, name from customer where
I have a SQL procedure that generates a util file as its output depending
I have created a function that takes a SQL command and produces output that
The PowerShell sqlps module provides core support for SQL Server access from within PowerShell
This tail -n 1217060 input.sql > /disk2/mysql_dump/output.sql is not writing to the output file.
I'm playing with the Output keyword in SQL Serer 2005 Express. I've written the
So far I've tried: 'date +%Y-%m-%d_%H%M'_PostsOnly.sql With output: date\ +%Y-%m-%d_%H%M_PostsOnly.sql 2) 'date +\%Y-\%m-\%d_\%H\%M_PostsOnly'.sql With
My sql stored procedure returns following output. type_id description ------- ----------- 1 Name details
I am trying to output results of 2 sql queries to one JSON file.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.