Database Connections

Database Connections

gsqlcmd requires a database connection as the first positional parameter in database-related modes.

You may use:

  • Database connection strings
  • Named connections
  • File names

Here is an example of the connection string use:

gsqlcmd exec "System.Data.OleDb;Provider=MSOLEDBSQL;Data Source=.\SQLEXPRESS;Initial Catalog=master;Integrated Security=SSPI" "select name from sys.databases"

You may pass connection strings using environment variables.

For example:

set connection="Provider=MSOLEDBSQL;Data Source=.\SQLEXPRESS;Initial Catalog=master;Integrated Security=SSPI"

gsqlcmd %connection% "select name from sys.databases"

Here is an example of the named connection use:

gsqlcmd exec master "select name from sys.databases"

Here is an example of the file name use:

gsqlcmd exec test.xlsx "SELECT * FROM [sheet1$]"

See more details in the connection parameter description.

You may easily create named connections using the edit-connections command like:

gsqlcmd edit-connections /local

Use the /local, /user, or /app option to edit connections of the specified configuration file.

The command starts gConnectionManager that allows creating, editing, copying, and deleting connection strings in a visual mode:

Use the show-connections mode to list defined connection string names. For example:

gsqlcmd show-connections

Use the /local, /user, or /app option to show connections of the specified configuration file.

For example:

gsqlcmd show-connections /user

Also, use the following options to filter connections of the specified platform:

/mssql, /sqlce, /mysql, /oracle, /db2, /nuodb, /pgsql, /snowflake, /sqlite, /dbf, /foxpro, /csv, /excel

For example:

gsqlcmd show-connections /app /oracle

Use the show-connection mode to show the specified connection properties.

For example:

gsqlcmd show-connection master

You may query specific connection properties like

gsqlcmd show-connection test.xlsx connectionString

Use the show-providers mode to show available data providers.

For example:

gsqlcmd show-providers /excel

Note that Windows has different 32-bit and 64-bit data providers.

Use gsqlcmd32.exe to work with 32-bit providers and connection strings in 64-bit Windows.

For example:

gsqlcmd32 show-providers /excel
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.