简体   繁体   English

如何使用R + DBI + ODBC和osx(和Windows VM)连接到Teradata数据库

[英]How to connect to Teradata Database using R + DBI +ODBC with osx (and windows VM)

I work on a Mac, but also have a windows VM. 我在Mac上工作,但也有Windows VM。

I am trying to connect to a Teradata Database on both my Mac and Windows VM using R with the DBI library (so I can use dbplyr). 我正在尝试使用带有DBI库的R连接到Mac和Windows VM上的Teradata数据库(以便可以使用dbplyr)。 Everything is working great on my Windows VM (see my previous question: Connect to Teradata Database using R + DBI library + ODBC ). 一切在我的Windows VM上都运行良好(请参阅我的上一个问题: 使用R + DBI库+ ODBC连接到Teradata数据库 )。

Again I suspect a driver issue, but I am not sure. 我再次怀疑是驱动程序问题,但我不确定。 I'm sure I had this working last week, but I can't remember. 我确定我上周有这个工作,但我不记得了。 I know I have updated my Mac. 我知道我已经更新了Mac。


Background: First here's my ODBC info if I look it the ODBC Administrator: 背景:首先,这是我的ODBC信息(如果我看它是ODBC Administrator):

  • Name = name_name 名称= name_name
  • Driver = Teradata 驱动程序= Teradata
  • Name or IP address = address.here.ok 名称或IP地址= address.here.ok
  • Mechanism = ldap 机制= ldap
  • Username = my_username 用户名= my_username

See an screenshot of my ODBC administrator 查看我的ODBC管理员的屏幕截图 ODBC管理员 and the drivers 和司机 司机

I downloaded the ODBC driver for Mac from Teradata 我从Teradata下载了Mac的ODBC驱动程序

I use R version 3.5.1 (2018-07-02) and the teradata driver 16.20. 我使用R版本3.5.1(2018-07-02)和Teradata驱动程序16.20。


What works (on Mac and Windows): library(RODBC) 有效的方法(在Mac和Windows上):库(RODBC)

con = odbcConnect(dsn = "name_name"
                  ,uid = rstudioapi::askForPassword("Username")
                  ,pwd = rstudioapi::askForPassword("Password")
                  )

What doesn't work on Mac (but works on Windows) 在Mac上不起作用(但在Windows上起作用)

con = DBI::dbConnect(odbc::odbc()
                  ,dsn = "name_name"
                  ,uid = rstudioapi::askForPassword("Username")
                  ,pwd = rstudioapi::askForPassword("Password")
                  )

On Mac I get the error Error: nanodbc/nanodbc.cpp:950: IM002: [unixODBC][Driver Manager]Data source name not found, and no default driver specified . 在Mac上,出现Error: nanodbc/nanodbc.cpp:950: IM002: [unixODBC][Driver Manager]Data source name not found, and no default driver specified

I have also tried other values in my connection string with no luck as described here , eg: 我也尝试过其他值在我的连接字符串描述没有运气在这里 ,如:

con = DBI::dbConnect(odbc::odbc()
                  ,Driver = "Teradata"
                  ,Host = "address.here.ok"
                  ,DBName = "name_name"
                  ,uid = rstudioapi::askForPassword("Username")
                  ,pwd = rstudioapi::askForPassword("Password")
                  )

Thankyou in advance. 先感谢您。

Edit: update 编辑:更新

Based on suggestions from @TallTed I checked the two locations where DBI will “look” for the odbc file. 根据@TallTed的建议,我检查了DBI将“查找” odbc文件的两个位置。

  • /usr/local/etc/ directory has files odbc.ini and odbcinst.ini but they're completely empty /usr/local/etc/目录包含文件odbc.iniodbcinst.ini但它们完全为空
  • /etc/ had neither odbc.ini or odbcinst.ini /etc/都没有odbc.iniodbcinst.ini

I also looked in the locations @TallTed suggested the DBI library would look: 我还查看了@TallTed建议使用的DBI库的位置:

  • /Users/*/Library/ODBC has both odbc.ini and odbcinst.ini . /Users/*/Library/ODBC具有odbc.iniodbcinst.ini odbc.ini is filled in with information and odbcinst.ini doesn't have much. odbc.ini充满了信息,而odbcinst.ini没有太多信息。
  • /Library/ODBC/ only has odbcinst.ini which is filled with information and an empty folder called ODBCDataSources (not sure if there are hidden files in there). /Library/ODBC/只有odbcinst.ini ,里面充满了信息,还有一个名为ODBCDataSources的空文件夹(不确定其中是否存在隐藏文件)。
  • /Users/*/.odbc.ini exists with nothing in it, I couldn't open /Users/*/.odbcinst.ini /Users/*/.odbc.ini存在,我无法打开/Users/*/.odbcinst.ini

So far, in /usr/local/etc/ I removed odbcinst.ini and odbc.ini and crated the following symlinks: 到目前为止,在/usr/local/etc/我删除了odbcinst.iniodbc.ini并创建了以下符号链接:

  • (link to odbc.ini file) ln -s /Users/*/Library/ODBC/odbc.ini /usr/local/etc (链接到odbc.ini文件) ln -s /Users/*/Library/ODBC/odbc.ini /usr/local/etc
  • (link to odbcinst.ini file) ln -s /Library/ODBC/odbcinst.ini /usr/local/etc (链接到odbcinst.ini文件) ln -s /Library/ODBC/odbcinst.ini /usr/local/etc
  • (link to ODBCDataSources folder) ln -s /Library/ODBC/ODBCDataSources /usr/local/etc (链接到ODBCDataSources文件夹) ln -s /Library/ODBC/ODBCDataSources /usr/local/etc

I couldn't create symlinks into /etc/ folder for example I got the error: 我无法在/etc/文件夹中创建符号链接,例如出现错误:

  • ln: /etc/odbc.ini: Permission denied

Now I get Error: nanodbc/nanodbc.cpp:950: HY000: [Teradata][ODBC] (11560) Unable to locate SQLGetPrivateProfileString function. 现在出现Error: nanodbc/nanodbc.cpp:950: HY000: [Teradata][ODBC] (11560) Unable to locate SQLGetPrivateProfileString function.

Edit 2: solution 编辑2:解决方案

con = DBI::dbConnect(odbc::odbc()
               ,driver = "/Library/Application Support/teradata/client/16.20/lib/tdataodbc_sbu.dylib"
               ,DBCName = "address.goes.here"
               ,MechanismName = "ldap"
               ,uid = rstudioapi::askForPassword("Username")
               ,pwd = rstudioapi::askForPassword("Password"))

The path /Library/Application Support/teradata/client/16.20/lib/tdataodbc_sbu.dylib is just from ODBC Administrator > Drivers tab 路径/Library/Application Support/teradata/client/16.20/lib/tdataodbc_sbu.dylib仅来自ODBC管理器>驱动程序选项卡

The ODBC Administrator you're running is working with the iODBC Driver Manager (which Apple ships with macOS). 您正在运行的ODBC管理器正在使用iODBC Driver Manager(Apple随macOS一起提供)。 iODBC looks to specific default locations for the ODBC configurations -- iODBC查找ODBC配置的特定默认位置-

/Library/ODBC/odbc.ini
/Library/ODBC/odbcinst.ini
/Users/*/Library/ODBC/odbc.ini
/Users/*/Library/ODBC/odbcinst.ini
/Users/*/.odbc.ini -> /Users/*/Library/ODBC/odbc.ini
/Users/*/.odbcinst.ini -> /Users/*/Library/ODBC/odbcinst.ini

Based on the success and failure you report, RODBC is apparently built against iODBC, but DBI is apparently built against the unixODBC Driver Manager, which looks to different default locations -- 根据您报告的成功和失败,RODBC显然是根据iODBC构建的,而DBI显然是根据unixODBC Driver Manager构建的,后者看起来在不同的默认位置-

/etc/odbc.ini
/etc/odbcinst.ini
/usr/local/etc/odbc.ini
/usr/local/etc/odbcinst.ini

You may find success by using the full [name_name] DSN definition as found in the relevant odbc.ini file to construct a DSN-less ODBC connect string for your DBI::dbConnect() call. 您可以通过使用在相关odbc.ini文件中找到的完整 [name_name] DSN定义来为DBI::dbConnect()调用构造一个无DSN的ODBC连接字符串来找到成功。

Alternatively, you might move (most of) the content of the latter files into the former files, and replace the latter files with symlinks to the others, such that both Driver Managers use the same configuration files -- even though some apps and some drivers will only work with one Driver Manager. 或者,您可以将后一个文件的(大部分)内容移到前一个文件中,并用与其他文件的符号链接替换后一个文件,以使两个驱动程序管理器都使用相同的配置文件-即使某些应用程序和某些驱动程序只能与一个驱动程序管理器一起使用。

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

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