How to create a report from the 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.

Create 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 [email protected], 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\

Note

The path to the executable file will differ depending on how you have installed the Studio - as a standalone tool or as part of the dbForge Edge bundle. Make sure that you have specified a correct path. If you have installed the Studio as part of dbForge Edge, change the path accordingly:

C:\Program Files\Devart\dbForge Edge\dbForge Studio for SQL Server>dbforgesql.com

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" 

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:"[email protected]"
  • 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.

Want to Find out More?

Overview

Overview

Take a quick tour to learn all about the key benefits delivered by dbForge Studio for SQL Server.
All Features

All features

Get acquainted with the rich features and capabilities of the Studio in less than 5 minutes.
Request a demo

Request a demo

If you consider employing the Studio for your business, request a demo to see it in action.
Ready to start using dbForge Studio for SQL Server?