Automate code formatting from the command line
Last modified: July 9, 2025
dbForge Studio for SQL Server allows you to use the command line to format the code.
Note
The command-line interface is available only in the Enterprise and Professional editions of dbForge Studio for SQL Server.
How to automate code formatting from the command line
1. Click Start.
2. In desktop mode, press Windows + R to show the Run command line.
3. In the window that opens, type cmd and press Enter.
4. Type a path to the dbforgesql.com
file located in the dbForge Studio for SQL Server installation folder on your PC.
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. Ensure you have specified a correct path.
If you have installed the Studio as part of dbForge Edge, change the path accordingly:
cd "C:\Program Files\Devart\dbForge Edge\dbForge Studio for SQL Server"
5. Press Enter.
6. Specify the formatting operation–formatsql
with the following parameters and arguments:
dbforgesql.com /formatsql /sourcefile:"D:\NoFormat.sql" /outputfile:"D:\Format.sql"
where:
D:\NoFormat.sql
is the path to the file you want to format.D:\Format.sql
is the path to the formatted results file.
Tip
To get quick help on the arguments available in the command line, run the following:
dbforgesql.com /formatsql /?
7. Press Enter to run the process.
Note
You can set the unlimited number of the required extensions:
dbforgesql /formatsql /sourcefolder:"c:\" /filextention:*.sql /filextention:*.prg /filextention:*.db1
Switches used in the command line
Select corresponding command line switches to perform the required operations:
Argument | Usage and Action |
---|---|
/argfile |
Usage: /argfile:<path> Path to the command line arguments file. The options specified in the command line have higher priority than the options which were given in the file. |
/activate |
Activate the product using the activation key. For more information, see the Activation topic. |
/connection |
Usage: /connection:<connection_string> Specify the connection string. For example, /connection:"Data Source=JordanS\MSSQLSERVER2019;Initial Catalog=AdventureWorks2019; User ID=yourusername;Password=yourpassword" |
/deactivate |
Deactivate the product. For more information, see the Deactivation topic. |
/encoding |
Usage: /encoding:<codepage|encoding name> Specify the encoding that should be applied to open and save files. For example, /encoding:"UTF-8" or /encoding:"65001" |
/errormode |
Usage: /errormode:<ignore|abort> Specify the application behavior when an error is encountered:ignore - to ignore all errors;abort - to cancel execution if any error occurs. |
/exitcodes |
The list of possible exit codes that can be returned by the command-line process. |
/filextension |
Usage: /filextension:*.<sql|prc|txt|...> Specify the extension of the source folder files that will be formatted. The .sql extension is selected by default. |
/formatsql |
Format SQL files with a specified profile. |
/includesubfolders |
Usage: /includesubfolders Include the current directory and all of its subdirectories in the search operation. |
/log |
Usage /log:<filepath> Generate a formatting log file in the specified directory. |
/outputfile |
Usage: /outputfile:<path> Specify the path to an output file where the formatting results of the source file will be saved (in this case, the source file is saved without changes). If the parameter is not specified, the formatting results will be saved in the source file. |
/outputfolder |
Usage: /outputfolder:<path> Specify the path to an output folder where the source folder files with the formatting results will be saved. The files from the source folder will not be changed. If the parameter is not specified, the formatting results will be saved in the source folder files. |
/password |
Usage: /password:<yourpassword> Specify the server password. This overrides the password specified in the connection string. |
/profile |
Usage: /profile:<path>|<profile name> Specify the path to the file that contains formatting options settings or a predefined profile name. If the parameter is not specified, default formatting options settings will be applied. For example, a profile shared through network with dev team: /profile:"\\pub\devteam\corporate_style_profile.xml" or a profile stored on a local machine: /profile:"D:\formatprofile\myprofile.xml" |
/quiet (/q ) |
Hide all messages in the console mode. |
/sourcefile |
Usage: /sourcefile:<path> Specify the source SQL file to be formatted. |
/soucefolder |
Usage: /sourcefolder:<path> Specify the path to the folder where the files for formatting are located. |
/treatwarningaserror |
Usage: /treatWarningAsError:[Yes|No] Yes : Treat all warnings as errors; further behavior is determined by the errormode option.No : Do not treat all warnings errors and execute with warning messages. |
Exit codes used in the command line
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 | Some arguments may not appear more than once in a command line. For example, /arg2 depends on /arg1 but you have specified /arg2 without specifying /arg1, or /arg2 cannot be used with /arg1, but you have used them both. |
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 scripts folder. |
105 | Resource unavailable | The file is missing. |
Want to find out more?
Overview
Take a quick tour to learn all about the key benefits delivered by dbForge Studio for SQL Server.
All features
Get acquainted with the rich features and capabilities of the tool in less than 5 minutes.
Request a demo
If you consider employing this tool for your business, request a demo to see it in action.