Automate code formatting from the command line

You can use the command line with dbForge Studio for SQL Server to format your SQL code.

Note

The command-line interface is available only in the Enterprise and Professional editions of dbForge Studio for SQL Server. For details about the feature availability, see Editions.

Run the formatting command

1. Press Windows logo key+R.

2. Type cmd, then press Enter.

3. Change the directory to the dbForge Studio for SQL Server installation directory that contains the dbforgesql.com file.

cd "C:\Program Files\Devart\dbForge Studio for SQL Server"

4. Press Enter.

Note

The default path to the dbforgesql.com file varies depending on whether you installed dbForge Studio as a standalone tool or as part of the dbForge Edge bundle.

If you installed dbForge Studio as part of dbForge Edge, the default path is as follows.

cd "C:\Program Files\Devart\dbForge Edge\dbForge Studio for SQL Server"

5. Enter the formatting command.

dbforgesql.com /formatsql /sourcefile:"D:\NoFormat.sql" /outputfile:"D:\Format.sql"

where:

  • formatsql – The name of the operation.

  • sourcefile – The full path to the file to format.

  • outputfile – The full path to the resulting formatted file.

Tip

To get quick help on the available command-line options, run dbforgesql.com /formatsql /?.

6. Press Enter to start the formatting.

Command-line options

Option Usage Description
connection /connection:<connection_string> The connection string.
encoding /encoding:<codepage|encoding name> Specifies the encoding to use when opening and saving files.
errormode /errormode:<ignore|abort> Specifies the application’s behavior when an error occurs:
ignore – Ignores the error.
abort – Cancels execution.
exitcodes /exitcodes Lists exit codes that can be returned by the command-line process.
filextension /filextension:*.<sql|prc|txt|...> The extension of the source folder files to format. The default value is .sql.
includesubfolders /includesubfolders Includes the current directory and its subdirectories in the search operation.
log /log:<filepath> The full path to the log file.
outputfile /outputfile:<path> The full path to the resulting formatted file. The source file remains unchanged.
If the parameter is not specified, the formatting results are saved in the source file.
outputfolder /outputfolder:<path> The path to the folder with the resulting formatted files. Files from the source folder remain unchanged.
If the parameter is not specified, the formatting results are saved in the source folder files.
password /password:<pw> The server password. It overrides the password specified in the connection option.
profile /profile:<path>|<profile name> The full path to the file that contains formatting settings or the name of a predefined profile.
If the parameter is not specified, default formatting settings are applied.
sourcefile /sourcefile:<path> The full path to the file to format.
sourcefolder /sourcefolder:<path> The path to the folder that contains the files to format.
treatwarningaserror /treatwarningaserror:[Yes|No] Specifies how to treat warnings:
Yes – Warnings are treated as errors; further behavior is determined by the errormode option.
No – Warnings aren’t treated as errors; execution continues with warning messages.

Command-line exit codes

Exit code Description Additional information
0 Success The operation has been completed without errors.
1 Unhandled exception Unhandled exception. See the log for more details.
10 Command line usage error The command line was used incorrectly. For example, an incorrect flag or incorrect syntax may have been used.
11 Illegal argument duplication Certain arguments may only appear once in a command line.
20 Trial expired Software trial period has expired, or the product has not been activated.
40 Server connection fail Server connection failed.
104 High-level parser error High-level errors were encountered while parsing a script folder.
105 Resource unavailable The file is missing.