简体   繁体   English

Teradata ODBC 驱动程序不能通过 Python 连接,但可以通过 VBA 连接

[英]Teradata ODBC driver not connecting via Python but able to connect via VBA

I have a strange problem where i am able to connect to Teradata using VBA but not able to connect via python from same teradata driver.我有一个奇怪的问题,我可以使用 VBA 连接到 Teradata,但无法从同一个 teradata 驱动程序通过 python 连接。

Below is the code snippet:下面是代码片段:

1) VBA 1) VBA

connection_string = "Driver={Teradata};" & "DBCName=" & dsn_name & ";Database=" & database_name & "; User ID =" & user_name & ";Password=" & password

and i am able to connect to teradata successfully.我能够成功连接到teradata。

2) Python 2) 蟒蛇

import pyodbc
dsn_name="td_dev"
user_name="test"
password="test"
db = pyodbc.connect('DSN=' + dsn_name + ';UID='+ user_name +';PWD=' + password + ';')

this statement throws me below error-此语句使我低于错误-

('IM003', '[IM003] Specified driver could not be loaded due to system error  126
: The specified module could not be found. (Teradata, C:\\Program Files (x86)\\T
eradata\\Client\\13.10\\ODBC Driver for Teradata\\Lib\\tdata32.dll). (160) (SQLD
riverConnect)')

I have tried various methods like : Re-Installing TD drivers, setting up the environment variables.我尝试了各种方法,例如:重新安装 TD 驱动程序、设置环境变量。

But the question remains, how i am able to connect via excel VBA but not python.但问题仍然存在,我如何能够通过 excel VBA 而不是 python 进行连接。

I think you need to add the driver argument.我认为您需要添加驱动程序参数。 It is possible that you have multiple teradata drivers.您可能有多个 teradata 驱动程序。 If that is the case you need to explicitly declare which driver to be used: Eg如果是这种情况,您需要明确声明要使用的驱动程序:例如

#To get a list of drivers
import pyodbc
pyodbc.drivers()

That will return a list of odbc drivers in your system.这将返回系统中的 odbc 驱动程序列表。 Output eg输出例如

['SQL Server',
 'SQL Server Native Client 10.0',
 'Amazon Redshift (x64)',
 'Microsoft Access Driver (*.mdb, *.accdb)',
 'Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)',
 'Microsoft Access dBASE Driver (*.dbf, *.ndx, *.mdx)',
 'Microsoft Access Text Driver (*.txt, *.csv)',
 'Teradata',
 'SQL Server Native Client 11.0',
 'PostgreSQL ANSI(x64)',
 'PostgreSQL Unicode(x64)',
 'MySQL ODBC 5.3 ANSI Driver',
 'MySQL ODBC 5.3 Unicode Driver',
 'Teradata Database ODBC Driver 16.10',
 'Teradata 7.1 DB2 Wire Protocol',
 'Teradata 7.1 Oracle',
 'Teradata 7.1 Oracle Wire Protocol',
 'Teradata 7.1 SQL Server Legacy Wire Protocol',
 'Teradata 7.1 SQL Server Wire Protocol',
 'Teradata 7.1 MySQL Wire Protocol',
 'Teradata 7.1 PostgreSQL Wire Protocol']

Since there is both Teradata and Teradata Database ODBC Driver 16.10.由于有 Teradata 和 Teradata Database ODBC Driver 16.10。 We need to declare which one to be used:我们需要声明使用哪一个:

host, username, password = 'hostname','UserName', 'Password'
tdConnect = pyodbc.connect('Driver=Teradata Database ODBC Driver 16.10;DBCNAME=%s;DSN=XXXX;UID=%s;PWD=%s'%(host, username, password),autocommit=True)

I hope that fixed your issue.我希望能解决你的问题。

In my case, I was able to fix this by following "Workaround" as described in https://knowledge.informatica.com/s/article/134879 , even though I'm not using Informatica nor Teradata 13.就我而言,即使我没有使用 Informatica 和 Teradata 13,我也能够按照https://knowledge.informatica.com/s/article/134879 中所述的“解决方法”解决此问题。

The workaround that solved my problem, "system error 126", which I was getting using Python, pyodbc, and Teradata ODBC drivers 14.10.00:解决我的问题“系统错误 126”的解决方法,我使用 Python、pyodbc 和 Teradata ODBC 驱动程序 14.10.00:

Copy all files in C:\\Program Files\\Teradata\\Client\\14.10\\Shared ICU Libraries for Teradata\\lib to the folder, C:\\Program Files\\Teradata\\Client\\14.10\\ODBC Driver for Teradata nt-x8664\\LibC:\\Program Files\\Teradata\\Client\\14.10\\Shared ICU Libraries for Teradata\\lib中的所有文件复制到文件夹C:\\Program Files\\Teradata\\Client\\14.10\\ODBC Driver for Teradata nt-x8664\\Lib

No reboot was required.不需要重新启动。 The next time I ran my python code, it successfully connected to Teradata via ODBC.下次我运行我的 python 代码时,它通过 ODBC 成功连接到 Teradata。

The fact that both Excel and the Teradata ODBC test utility, C:\\Program Files\\Teradata\\Client\\14.10\\ODBC Driver for Teradata nt-x8664\\Bin\\tdxodbc.exe were able to make ODBC connections BEFORE I made this change is weird. Excel 和 Teradata ODBC 测试实用程序C:\\Program Files\\Teradata\\Client\\14.10\\ODBC Driver for Teradata nt-x8664\\Bin\\tdxodbc.exe能够我进行此更改之前建立 ODBC 连接这一事实很奇怪. It tells me that pyodbc uses a different mechanism to resolve ODBC DLL dependencies than both Excel and Teradata's ODBC test utilty.它告诉我 pyodbc 使用与 Excel 和 Teradata 的 ODBC 测试实用程序不同的机制来解决 ODBC DLL 依赖项。 It's probably something to do with what's in the PATH variable as modified by Teradata's installer.这可能与 Teradata 安装程序修改的 PATH 变量中的内容有关。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM