Connecting to Professional Drivers

Overview

This page contains instructions for connecting to Posit Professional Drivers using R and Python.

Steps

The general flow for connecting to Professional Drivers is to install the appropriate package for your language, then test connectivity.

Install the odbc package

Use the odbc package to access your database with R:

  • From an R prompt, install odbc. Installing odbc also installs DBI, the database interface for R:

    R Console
    install.packages("odbc")
    Note

    On Linux, odbc requires the following system dependencies in Linux:

    • C++11
    • GCC 4.8 or later

    On older versions of RHEL, you can install GCC 4.8 with RedHat Developer Toolset:

    sudo yum install devtoolset-4-gcc-c++

Test connectivity

  • Test your connection in R with odbc::odbc().

    • If you are using the RStudio IDE, you can use the New Connection dialog to help you write the connection string. For example:

      R Console
      con <- DBI::dbConnect(odbc::odbc(),
              Driver = "Driver Name",
              Database = "Database",
              UID = "User",
              PWD = "Password",
              Server = "Server",
              Port = 5432)
    • If you have a predefined DSN as shown in the Professional Drivers Installation section, you can connect using a DSN name, for example:

      R Console
      con <- DBI::dbConnect(odbc::odbc(), "DSN Name Here")

Install the pyodbc package

Use the pyodbc package to access your database with Python.

  • From the terminal, install pyodbc:

    pip install pyodbc

    Per the pyodbc installation documentation,

    Starting with pyodbc 4.0.35, Linux wheels are available from PyPI. However, they don’t include their own copies of the unixODBC library files (because that caused problems), so if pip installs pyodbc from those wheel files then unixODBC must be installed separately. Ensure you have unixodbc installed on the server.

Test connectivity

  • Test your connection in Python with pyodbc.connect
    • If you are using credentials to connect to a database, include them either as a connection string or as keyword arguments. For example:

      Python Interpreter
      import pyodbc
      con=pyodbc.connect(driver='{Driver Name}',
                         database='Database',
                         uid='User',
                         pwd='Password',
                         server='Server',
                         port=5432)
    • If you have a predefined DSN as shown in the Professional Drivers Installation section, you can connect using a DSN name, for example:

      Python Interpreter
      import pyodbc
      con=pyodbc.connect('DSN=DSN Name Here')

Additional Resources

Visit the User guide for best practices, examples, and additional configurations to use when working with databases and the Posit Professional Drivers.