ODBC

Connect & Extract data from databases via Open Database Connectivity (ODBC)

Open Database Connectivity (ODBC) provides a standardized interface for accessing various databases using ODBC drivers. This connector enables data extraction from databases that may not have a dedicated Sling connector, or when ODBC is the preferred access method. This is available starting v1.5.3.

Setup

Before using ODBC connections, ensure you have the appropriate ODBC driver installed for your database:

macOS (via Homebrew):

# SQL Server
brew install microsoft/mssql-release/msodbcsql18

# PostgreSQL
brew install psqlodbc

# MySQL
brew install mysql-connector-odbc

Linux (Debian/Ubuntu):

# SQL Server
curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
sudo add-apt-repository "$(curl https://packages.microsoft.com/config/ubuntu/$(lsb_release -rs)/prod.list)"
sudo apt-get update
sudo apt-get install msodbcsql18

# PostgreSQL
sudo apt-get install odbc-postgresql

# MySQL
sudo apt-get install libmyodbc

Windows: Download and install the appropriate ODBC driver from the vendor's website.

Connection Properties

  • conn_string (required) -> The ODBC connection string (DSN or DSN-less format)

  • conn_template (optional) -> Specify the SQL template name to use for query syntax. This should be the name of a template (e.g., sqlserver, postgres, mysql, db2, sap_hana). If not provided, Sling auto-detects from the connection string.

Custom Templates for Unsupported Drivers

For ODBC drivers that connect to databases not natively supported by Sling (e.g., DB2, SAP HANA, Teradata), you can create your own custom template:

  1. Create a template file at ~/.sling/templates/{template_name}.yaml (e.g., ~/.sling/templates/db2.yaml)

  2. Define the SQL syntax and type mappings specific to your database (see Template Overrides for the template structure)

  3. Reference the template name in your connection's conn_template property

For example, to connect to DB2 via ODBC:

Then reference it in your connection:

Using sling conns

Environment Variable

Sling Env File YAML

See here to learn more about the sling env.yaml file.

Replication Example

Here's an example replication configuration to extract data from an ODBC source to PostgreSQL:

Connection String Formats

DSN (Data Source Name)

Use a pre-configured DSN from your ODBC configuration:

DSN-less (Driver-based)

Connect directly without a DSN:

SQL Server:

PostgreSQL:

MySQL:

Troubleshooting

Driver Not Found

If you receive a "driver not found" error, verify that:

  1. The ODBC driver is installed

  2. The driver name in your connection string matches exactly (including brackets and version)

  3. On Linux/macOS, check /etc/odbcinst.ini for installed drivers

SQL Syntax Errors

If you encounter SQL syntax errors (e.g., LIMIT vs TOP), ensure:

  1. The driver type is being correctly auto-detected from your connection string

  2. Or explicitly set conn_template to match your database type

Connection Timeout

For slow connections, you may need to add timeout parameters to your connection string:

If you are facing issues connecting, please reach out to us at [email protected], on discord or open a Github Issue here.

Last updated

Was this helpful?