How to connect to TIBCO Data Virtualization from Python using an ODBC DSN on Windows?

How to connect to TIBCO Data Virtualization from Python using an ODBC DSN on Windows?

book

Article ID: KB0072145

calendar_today

Updated On:

Products Versions
TIBCO Data Virtualization 8.0.x and higher.

Description

How to connect to TIBCO Data Virtualization from Python using an ODBC DSN on Windows?

Resolution

A Python script may be used to connect to TDV (TIBCO Data Virtualization) using an ODBC DSN created on Windows. The steps are below.

1.   If a TDV ODBC driver is not already installed on the Window box, install the ODBC driver.
      The latest driver may be downloaded from https://edelivery.tibco.com/

2.   Use the Microsoft ODBC Manager to create a systems DSN, for example TDV_DSN1.

        User-added image

3.   Decide on a published resource that the Python script will query.
      For example, the screenshot below shows a published resource named  ViewOrder.

        User-added image

4.     Create a Python script, as shown in the example below. 

test.py
     import pyodbc
     conn = pyodbc.connect('dsn=' + " TDV_DSN1")
     conn.setdecoding(pyodbc.SQL_CHAR, encoding='utf-8')
     conn.setencoding(encoding='utf-8')
     sql = " select * from ViewOrder"
     cur = conn.cursor().execute(sql)
     for row in cur:
         print(row)

The script does the following:
  • Reads the DSN to obtain the TDV ODBC driver location and the TDV server connection details.
  • Opens a connection.
  • Runs a SQL query on the published resource.
Output of the script:
User-added image
 

Issue/Introduction

How to connect to TIBCO Data Virtualization from Python using an ODBC DSN on Windows?