You can automate code formatting using the command line.
Note
The command-line interface is available only in certain editions of dbForge Studio for SQL Server. For detailed information on the features availability in the dbForge Studio editions, please refer to the Editions page.
1. Click Start.
2. Type cmd in the Search programs and files text box and press Enter.
Note
To run the Command Line in Windows 10:
From the Desktop Mode
- Move the mouse cursor to the exact lower left corner until the desktop shortcuts menu appears.
- Right-click to see the shortcut menu and than click Run.
From the Charms Bar
- Move your mouse to the upper right corner until the Charms Bar appears.
- Select Apps from the list and type ‘run’ in the search box.
- Click Run from the search results.
Use Windows + R Shortcut Keys
- In desktop mode, press the Windows + R keys, to show the Run command line.
- In the window that opens, type cmd and press Enter.
3. Type a path to the dbforgesql.com file located in the dbForge Studio for SQL Server installation folder on your PC, and then press ENTER.
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:
cd "C:\Program Files\Devart\dbForge Edge\dbForge Studio for SQL Server"
4. Specify the operation you want to perform (code formatting) and the required parameters and arguments:
dbforgesql.com /formatsql /sourcefile:"D:\NoFormat.sql" /outputfile:"D:\Format.sql"
Tip: To see a quick help on the arguments available in the command line, type the following:
dbforgesql.com /formatsql /?
5. Press ENTER to run the process.
Select corresponding command line switches to perform the required operations:
Argument | Action and Usage |
---|---|
/connection | Usage: /connection:<connection_string> Specify the connection string. |
/encoding | Usage: /encoding:<codepage|encoding name> Specify the encoding which should be applied to open and save files. |
/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 | List possible exit codes that can be returned by the command-line process. |
/filextension | Usage: /filextension:*.<sql|prc|txt|...> Specify the extension of the sourcefolder files that will be formatted. The .sql extension is chosen by default. |
/includesubfolders | Usage: /includesubfolders Include the current directory and all subdirectories in search operation. |
/log | Usage: /log:<filepath> Generate formatting log file in the specified directory. |
/outputfile | Usage: /outputfile:<path> Specify the path to an output folder where the sourcefolder files with formatting results will be saved. (Files from the source folder will not be changed). If the parameter is not specified, the formatting results will be saved in the sourcefolder files. |
/outputfolder | Usage: /outputfolder:<path> Specify the path to an output folder where the sourcefolder files with formatting results will be saved. (Files from the source folder will not be changed). If the parameter is not specified, the formatting results will be saved in the sourcefolder files. |
/password | Usage: /password:<pw> Specify the server password. Override the password specified in the connection string. |
/profile | Usage: /profile:<path>|<profile name> Specify the path to file that contains formatting options settings or predefined profile name. If the parameter is not specified, default formatting options settings will be applied. |
/sourcefile | Usage: /sourcefile:<path> Specify the source SQL file to be formatted. |
/sourcefolder | Usage: /sourcefolder:<path> Specify the path to folder where the files for formatting are located. |
/treatwarningaserror | Usage: /treatWarningAsError:[Yes|No] Yes: Treat all warnings as errors and further behavior is determined by the errormode option. No: Do not consider all warnings as errors and execute with warning messages. |
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. |