0
votes

I need to connect to the Teradata database using python. I have used the below code:

import pyodbc
import teradata



cnxn = pyodbc.connect('DRIVER={Teradata};SERVER=<*ServerName*>;DATABASE=<*Database Name*>;UID=<*User ID*>;PWD=<*Password*>',ansi=True, autocommit=True)

cur = cnxn.cursor()

But on executing, I am getting the error as :

Error: ('28000', '[28000] [Teradata][ODBC Teradata Driver] Not enough information to log on (0) (SQLDriverConnect); [28000] [Teradata][ODBC Teradata Driver] Not enough information to log on (0)')

What I am missing here ? What else needs to be included to set up the connection ?

Also, is there any other way to set up the connection. While looking, I have come across teradata.UdaExec(). Can this also be used?

1
The connectionstrings.com page here seems to suggest using DBCName= instead of SERVER=. Have you tried that?Gord Thompson
are you connecting from a Linux server?rogue-one

1 Answers

1
votes

The following works in CentOS Linux server.

create a file with the below contents in any file (say odbc.ini)

[ODBC Data Sources]
my_data_source=tdata.so

[my_data_source]
Driver=/path/to/teradata/drivers/tdata.so
DBCName=<td_hostname>
LastUser=<user_name>
Username=<user_name>
Password=<password>
Database=<default_database>
DefaultDatabase=<default_database>
TDMSTPortNumber=<teradata_port>

set ODBCINI variable to the path of the odbc file

export ODBCINI=/file/to/path/of/odbc.ini

note: you can skip the setting of ODBCINI env variable by creating the odbc.ini file in the home directory i.e. /home/user/.odbc.ini (note that the .odbc.ini is a hidden file with a dot prefix in the file name)

now to connect to Teradata use the below snippet.

import pyodbc
pyodbc.pooling = False
conn = pyodbc.connect('DSN=my_data_source',ansi=True, autocommit=True)