Creating a Report through Command Line

You can automate report creation process using command line. Such possibility can be very useful if you need to create a report using the same report file. For this, you will need to create a report template to use it afterwards in the command line. Note that some parameters can be specified directly in the command line. In this case values of these parameters specified in your template file will be overridden.

The walkthrough described further in this topic will show you how to use command line in order to automate the following data report routines: saving a report on disk in the HTML format, sending it by email and FTP.

Creating a Report Template

To create a report template, you should perform the following actions:

  1. Click Design New Report on the Data Analysis tab of the product Start Page. Data Report Wizard opens.
  2. Follow the wizard pages to create a report template file with the .rdb extension.
  3. Compose the report template.
  4. Save the file for future usage.

Prerequisites

  • To complete the following walkthrough, you need to have an already created report file with *.rdb extension. Refer to the corresponding tutorials to create data-aware and master-detail report files that can be used in command line as input files.
  • In this walkthrough, the Report1.rdb file, created in Creating a Simple Data-Aware Report will be used.

  • To send the generated report by email, open the SMTP, Environment, Options dialog box, and configure the email account settings. The following screen shot shows settings for a Gmail account:

    SMTP Options

Working with Data Reports

Suppose you need to send a data report containing customers’ address and phone number list in HTML format to your authorities via e-mail and FTP every day. For this, you have a report template Report1.rdb (the file is located in C:\dbForge Studio\Reports\), the folder on disk to which the report should be saved is C:\dbForge Studio for SQL Server\Reports\Output\, the e-mail address of your authorities is my_chief@company.com, the address of your FTP server is ftp://myftphost.net/reports/, login is send-report, and password is report.

To accomplish such task through command line, you need to perform the following steps:

  1. Open Command Prompt by pressing Win+R and type cmd in the Open text box.

  2. Change the path available in your Command Prompt window to the path where the dbforgesql. file located in the dbForge Studio for SQL Server installation folder (by default it’s C:\Program Files\Devart\dbForge Studio for SQL Server\). For this, use the cd operator:
    C:\Users\User>cd C:\Program Files\Devart\dbForge Studio for SQL Server\
    

    Press ENTER. You can see that the path has changed:

    C:\Program Files\Devart\dbForge Studio for SQL Server>
    
  3. Now, call the dbforgesql file with the .com extension:
    C:\Program Files\Devart\dbForge Studio for SQL Server>dbforgesql.com
    
  4. Specify the /datareport operation switch:
    C:\Program Files\Devart\dbForge Studio for SQL Server>dbforgesql.com /datareport
    
  5. Specify the path to your Report1.rdb input file and the name of the file itself:
    C:\Program Files\Devart\dbForge Studio for SQL Server>dbforgesql.com /datareport /reportfile:"C:\dbForge Studio for SQL Server\Reports\Report1.rdb"
    
  6. Specify the format you want to save your report in. In this case it’s HTML:

    C:\Program Files\Devart\dbForge Studio for SQL Server>dbforgesql.com /datareport /reportfile:"C:\dbForge Studio for SQL Server\Reports\Report1.rdb" /format:HTML
    
  7. (Optional) To include parameters declared in a query script to command line, you can use the /parameters operation. For example, the following query script:
    SELECT
     Person.FirstName,
     Person.MiddleName,
     Person.LastName,
     Person.EmailPromotion
    FROM Person.Person
     WHERE BusinessEntityID = @Client_Id and PersonId in (@PersonsParam)
    

    will look as follows:

    dbforgesql.com /datareport /reportfile:Report.rdb /parameters:Client_Id="25" PersonsParam="3211,22123,123122" 
    
  8. To start working with the result file, type the /result operation.
  • To save your report in the specified folder on disk, type the path to this folder:

    C:\Program Files\Devart\dbForge Studio for SQL Server>dbforgesql.com /datareport /reportfile:"C:\dbForge Studio for SQL Server\Reports\Report1.rdb" /format:HTML /result folder:"C:\dbForge Studio\Reports\Output\"
    
  • To send your report by email, add the email address:

    C:\Program Files\Devart\dbForge Studio for SQL Server>dbforgesql.com /datareport /reportfile:"C:\dbForge Studio for SQL Server\Reports\Report1.rdb" /format:HTML /result email:"address@hostname.net"
    
  • To send your report by FTP, specify the host, login, and password:

    C:\Program Files\Devart\dbForge Studio for SQL Server>dbforgesql.com /datareport /reportfile:"C:\dbForge Studio for SQL Server\Reports\Report1.rdb" /format:HTML /result folder:"ftp://myftphost.net/reports/ " ftplogin:send-report ftppassword:report
    

Notes

  • If your report is in HTML format and consists of several files or folders, it is not possible to send such report by email or FTP using command line interface.

  • You can perform two actions at a time with the result: save it on disk and send by e-mail, or send it by FTP and e-mail.

  • If you need to create the same report and perform the same action with the result frequently, you can save the needed command line in a *.bat file and run it each time you need to create a report. In this case you will not have to type all necessary operators manually in Command Prompt any more.

  • To see quick help on the arguments available in the command line, you can type /datareport /?

For more information on the command line arguments for /datareport, refer to the Additional /datareport Arguments topic.