gsqlcmd Configuration File

gsqlcmd Configuration File

You can specify application settings, data providers, connections, and logging options in the gsqlcmd.exe.config and gsqlcmd32.exe.config configuration files.

Here is a configuration file sample:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings>
    <!--<add key="AppCulture" value="en-US"/>-->
    <add key="ConnectionTimeout" value="-1"/>
    <add key="CommandTimeout" value="300"/>
    <add key="SingleTags" value="meta,link,base,br,hr,img,input,wbr,col"/>
    <add key="AutoCorrectedTags" value="li,p,a"/>
    <add key="NewLineTags" value="p,div,h1,h2,h3,h4,h5,h6,hr,table,tr,th,td,ol,ul,li,form,head,meta,title,body,/body,/html"/>
    <add key="CutTags" value="script,noscript,style,link,meta,iframe"/>
    <add key="CutAttributes" value="style,onload,onmouseover,onmousedown,onmouseout,onchange,onclick,bgcolor"/>
    <add key="CutIDs" value=""/>
    <add key="CutComments" value="0"/>
    <!--<add key="CutScripts" value="0"/>-->
    <!--<add key="CutStyles" value="0"/>-->
    <!--<add key="Accept" value="application/json"/>-->
    <!--<add key="UserAgent" value="gsqlcmd 6.0"/>-->
  </appSettings>
  <system.data>
    <DbProviderFactories>
      ...
    </DbProviderFactories>
  </system.data>
  <connectionStrings>
    <add name="master" connectionString="Provider=MSOLEDBSQL;Data Source=.\SQLEXPRESS;Initial Catalog=master;Integrated Security=SSPI" providerName="System.Data.OleDb" />
    <add name="mssql" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=Test;Password=pass;User ID=user" providerName="System.Data.SqlClient" />
    <add name="mysql" connectionString="Server=localhost;Password=pass;User ID=user;Database=Test" providerName="MySql.Data.MySqlClient" />
    <add name="ora" connectionString="Provider=OraOLEDB.Oracle;Password=pass;User ID=user;Data Source=localhost/Test;PLSQLRSet=True" providerName="System.Data.OleDb" />
    <add name="db2" connectionString="Driver=IBM DB2 ODBC DRIVER;Hostname=localhost;Port=50000;Protocol=TCPIP;Database=Test;Pwd=pass;UID=user;LONGDATACOMPAT=1" providerName="System.Data.Odbc" />
    <add name="nuodb" connectionString="Server=localhost;Password=pass;User=user;Database=Test" providerName="NuoDb.Data.Client" />
    <add name="pgsql" connectionString="Server=localhost;Password=pass;User ID=user;Database=rtd" providerName="Npgsql" />
    <add name="sqlce" connectionString="Data Source=test.sdf" providerName="System.Data.SqlServerCe.4.0" />
    <add name="sqlite" connectionString="Data Source=test.db;Version=3;" providerName="System.Data.SQLite" />
  </connectionStrings>
  <system.diagnostics>
    <switches>
      <add name="TraceSQL" value="0"/>
    </switches>
    <trace autoflush="false" indentsize="0">
      <listeners>
        <!--<remove name="Default" />-->
        <!--<add name="Console"  type="System.Diagnostics.ConsoleTraceListener" />-->
        <!--<add name="Logfile"  type="System.Diagnostics.TextWriterTraceListener" initializeData="gsqlcmd.log" />-->
      </listeners>
    </trace>
  </system.diagnostics>
</configuration>

Configuration File Locations

gsqlcmd reads configuration files from three locations:

  • The folder where gsqlcmd.exe located
  • %LocalAppData%\Gartle\gsqlcmd
  • Current folder

The configuration file in the gsqlcmd.exe folder can contain all sections.

The configuration files in other folders can contain the connectionStrings section only.

connectionStrings

The connectionStrings section contains named connection strings.

So, you can use defined names in the <connection> parameter like:

gsqlcmd exec master "select name from sys.databases"

Use the edit-connections mode with the /local, /user, and /app options to edit connections in a visual mode using gConnectionManager.

Use the show-connections mode to show connections.

appSettings

Use this section to define default application settings.

You can change the default settings in run-time using the options with the same names like:

/commandTimeout, /connectionTimeout, /autoCorrectedTags, /cutAttributes, /cutComments, /cutScripts, /cutStyles, /cutIDs, and /cutTags.

system.data

This section contains definitions of data providers shipped with gsqlcmd.

Usually, you do not need to modify this section.

system.diagnostics

You can use this section to turn on tracing SQL commands and to define a log file.

To turn on tracing SQL commands, set the TraceSQL switch value to 1.

To define the log file, uncomment its line and edit the paths in the initializeData attribute.