我使用 Teradata SQL Assistant 连接到Teradata。连接参数包括服务器地址和驱动程序(出于隐私原因更改了服务器信息),如下所示:
Name: my_teradata_connection
Teradata Server Info: 00.11.22.333
Data Source: Teradata Database ODBC Driver 16.20
UID: My_User_ID
PWD: My_PWD
我正在尝试使用DBI
和odbc
软件包使用R连接到Teradata。
con <- DBI::dbConnect(odbc::odbc(),
Driver = "[your driver's name]",
Host = "[your server's path]",
DBCName = "[IP Address or Alias]"
UID = rstudioapi::askForPassword("Database user"),
PWD = rstudioapi::askForPassword("Database password"))
显然Driver
应该是Teradata Database ODBC Driver 16.20
。但是我应该把Teradata Server Info
放在哪里00.11.22.333
放在哪里?它应该填充Host
还是DBCName
参数?不管它不填充哪一个,那里都会有什么?
答案 0 :(得分:2)
通常,在包括ODBC连接在内的大多数DB-API中, server 和 host 是同义词,在其中您不会同时看到这两个关键字(当然也有例外)。具体来说,对于每个odbc
documentation,dbConnect
保持可选 server
参数:
dbConnect(
drv,
dsn = NULL,
...,
timezone = "UTC",
timezone_out = "UTC",
encoding = "",
bigint = c("integer64", "integer", "numeric", "character"),
timeout = 10,
driver = NULL,
server = NULL,
database = NULL,
uid = NULL,
pwd = NULL,
dbms.name = NULL,
.connection_string = NULL
)
但是,...
表示特定于相应驱动程序的其他ODBC驱动程序关键字,这里是Terdata ODBC驱动程序。
...附加的ODBC关键字,这些关键字将与其他参数一起加入 形成最终的连接字符串
并且从用于Teradata 16.20的ODBC驱动程序中,documentation,Driver
和DBCName
是必需的关键字。DBCName
似乎与服务器或主机给出IP地址或别名指示。
DBCName =
<IP-addr-or-alias>
| Keyword/Synonym | Description |
|-------------------------------------------------------------|-----------------------------------------------------------------------------------------|
| Driver=<driver-path> | [Required] The full path to the ODBC Driver for Teradata shared objects… |
| Description=<data-source-desc> | [Optional] Descriptive text about the data source. |
| DBCName=<IP-addr-or-alias> | [Required] The IP address or FQDN (fully qualified domain name) of the Teradata server… |
| Username=<name> or UID=<name> | [Optional] The default username for logging onto a Teradata server system. |
| Password=<password> | [Optional] The password required for the default Username. |
| DefaultDatabase=<database-name> Or Database=<database-name> | [Optional] The default database associated with the specified data source… |
| UPTMode | Default = NOTSET… |
因此,在R中,仅使用DBCName
。下面添加了可选的Database
关键字。
# KEYWORD APPROACH
con <- DBI::dbConnect(odbc::odbc(),
Driver = "Teradata Database ODBC Driver 16.20",
DBCName = "00.11.22.333",
Database = "myDatabase",
UID = rstudioapi::askForPassword("Database user"),
PWD = rstudioapi::askForPassword("Database password"))
# CONNECTION STRING APPROACH
con_str = "Driver={Teradata Database ODBC Driver 16.20};DBCName=00.11.22.333;Database=myDatabase;"
con <- DBI::dbConnect(odbc::odbc(),
.connection_string = con_str,
UID = rstudioapi::askForPassword("Database user"),
PWD = rstudioapi::askForPassword("Database password")