Command Line Parameters

Command Line Parameters


The parameter defines a connection to a database.

There are three options to specify the connection:

  1. A connection name defined in gsqlcmd.exe.config (or gsqlcmd32.exe.config for gsqlcmd32.exe).
  2. A connection string in the OLEDB, ODBC, or DSN format.
  3. A .NET Framework data provider name and a connection string separated by a semicolon.

The first option is the best as you use short names of encrypted connection strings stored in the configuration files.

For example, gsqlcmd.exe.config can contain the following lines (in the unencrypted mode):

<?xml version="1.0" encoding="utf-8" ?>
    <add name="AzureDemo" connectionString="Provider=SQLOLEDB;Data Source=.\SQLEXPRESS;Initial Catalog=AzureDemo;Integrated Security=SSPI"
      providerName="System.Data.OleDb" />
    <add name="rtd-mssql" connectionString="Data Source=.;Initial Catalog=RTD;Password=r#td_2014_abc!;User ID=rtd"
      providerName="System.Data.SqlClient" />
    <add name="rtd-sqlce" connectionString="Data Source=%LOCALAPPDATA%\Gartle\RealTimeToDB\rtd.sdf"
      providerName="System.Data.SqlServerCe.4.0" />
    <add name="rtd-mysql" connectionString="Server=localhost;Password=r#td_2014_abc!;User ID=rtd;Database=rtd"
      providerName="MySql.Data.MySqlClient" />
    <add name="rtd-ora" connectionString="Provider=OraOLEDB.Oracle;Password=r#td_2014_abc!;User ID=RTD;Data Source=Oracle/Orcl;PLSQLRSet=True"
      providerName="System.Data.OleDb" />
    <add name="rtd-db2" connectionString="Driver=IBM DB2 ODBC DRIVER;Hostname=DB2;Port=50000;Protocol=TCPIP;Database=SAMPLE;Pwd=r#td_2014_abc!;UID=RTD;LONGDATACOMPAT=1"
      providerName="System.Data.Odbc" />
    <add name="rtd-nuodb" connectionString="Server=localhost;Password=r#td_2014_abc!;User=RTD;Database=rtd"
      providerName="NuoDb.Data.Client" />
    <add name="rtd-pgsql" connectionString="Server=localhost;Password=r#td_2014_abc!;User ID=rtd;Database=rtd"
      providerName="Npgsql" />

This allows using names like AzureDemo, rtd-mssql, rtd-sqlce, and others as the command line connection parameter.

Use the LocalConfig, UserConfig, and AppConfig gsqlcmd modes to edit configurations files in a visual mode using gConnectionManager.

The second option allows specifying connection strings for OLE DB providers, ODBC drivers, and DSN files.

For example:

gsqlcmd "Provider=SQLOLEDB;Data Source=.\SQLEXPRESS;Initial Catalog=AzureDemo;Integrated Security=SSPI" framework-install-en.sql

You may pass connection strings in environment variables. For example:

set connection=Provider=SQLOLEDB;Data Source=.\SQLEXPRESS;Initial Catalog=AzureDemo;Integrated Security=SSPI

gsqlcmd "%connection%" framework-install-en.sql 

Use double quotes for such variables.

In the third connection option, use a .NET Framework provider name before the connection string and separate it with a semicolon.

For example:

gsqlcmd "MySql.Data.MySqlClient;Server=localhost;Password=r#td_2014_abc!;User ID=rtd;Database=rtd" framework-install-en.sql

<SQL Query> | <SQL File>

This positional parameter defines the inline SQL query or the SQL script file name of the execute mode.

For example:

gsqlcmd rtd-ora "SELECT * FROM SYS.ALL_USERS"

gsqlcmd rtd-ora rtd-setup-ora.sql

gsqlcmd tries to read the script from the file first. If the file does not exist, gsqlcmd uses the parameter as an inline query.

<CSV File>

This parameter defines the input CSV file.

<Output File>

This optional parameter defines an output file name.

gsqlcmd writes the output to the console by default.

gsqlcmd detects the output file format using the file extension:

  • *.txt - text format;
  • *.csv - CSV;
  • *.htm or *.html - HTML.

Use the /AsText, /AsCSV, and /AsHTML options to specify the output format explicitly.

This website is using cookies. By continuing to browse, you give us your consent to our use of cookies as explained in our Cookie Policy.