Connecting to Teradata with R through DBI and ODBC - r

I connect to Teradata using the Teradata SQL Assistant. The connection parameters consist of a server address and a driver (server info changed for privacy reasons), as shown below:
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
I am trying to use R to connect to Teradata, using the DBI and odbc packages.
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"))
It seems obvious the Driver should be Teradata Database ODBC Driver 16.20. But where do I put the Teradata Server Info that we'll say is 00.11.22.333? Should it populate the Host or the DBCName arguments? And whichever one it does not populate, what will go there?

Usually, in most DB-APIs including ODBC connections server and host are synonymous keywords where you will not see both together but only one (of course with exceptions). Specifically, per odbc documentation, dbConnect maintains the optional server argument:
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
)
However, the ... indicates additional ODBC driver keywords that would be specific to corresponding driver, here being Terdata ODBC driver.
... Additional ODBC keywords, these will be joined with the other arguments to
form the final connection string
And from ODBC Driver for Teradata 16.20 documentation, Driver and DBCName are required keywords.DBCName appears to be synonymous to server or host given the IP address or alias indication.
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… |
Therefore in R, use the DBCName only. Below adds in the optional Database keyword.
# 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")

Related

RPostgreSQL - SCRAM error when trying to connect to local database

I am trying to connect to my localhost postgres DB and I get the following error.
library("RPostgreSQL")
drv <- dbDriver("PostgreSQL")
connec <- dbConnect(drv, dbname = "dbnamehere", port = 5432,user = "some_username", password = "somepassword")
Error in postgresqlNewConnection(drv, ...) :
RPosgreSQL error: could not connect admin_sci4i#localhost:5432 on dbname "website": SCRAM authentication requires libpq version 10 or above
It seems related to authentication security but I am having a local DB.. Is there any way to do anything in pgAdmin 4 and avoid this error (even if it is less secure)?
Surprisingly I managed to connect using other packages
library("RODBC")
library("odbc")
library("RPostgres")
con <- dbCanConnect(RPostgres::Postgres(),dbname="dbnamehere",port = 5432,user = "some_username", password = "somepassword")
con # Checks connection is working
con1 = dbConnect(RPostgres::Postgres(),dbname="dbnamehere",port = 5432,user = "some_username", password = "somepassword")
con1 # Checks connect
dbListTables(con1) # See tables
A nice explanation and walkthrough here.

odbc package in R throwing caught segfault error while connecting to Oracle Database

I am trying to connect to oracle database using odbc package in R and while connecting it is throwing caught segfault and we are unable to connect to database. Please find the details mentioned below and we have configured unixodbc configuration in the server but with RODBC package, we are able to establish the connection.
library(odbc)
Target2Conn<-dbConnect(odbc::odbc(), dsn = "PEGA_DEV", uid = "username", pwd = "username_123")
* caught segfault *
address 0x38, cause 'memory not mapped'
Traceback:
1:
odbc_connect(connection_string, timezone = timezone, timezone_out = timezone_out, encoding = encoding, bigint = bigint, timeout = timeout)
2:
OdbcConnection(dsn = dsn, ..., timezone = timezone, timezone_out = timezone_out, encoding = encoding, bigint = bigint, timeout = timeout, driver = driver, server = server, database = database, uid = uid, pwd = pwd, dbms.name = dbms.name, .connection_string = .connection_string)
3: .local(drv, ...)
4:
dbConnect(odbc::odbc(), dsn = "PEGA_DEV", uid = "username", pwd = "username_123")
5:
dbConnect(odbc::odbc(), dsn = "PEGA_DEV", uid = "username", pwd = "username_123")
Possible actions:
1: abort (with core dump, if enabled)
2: normal R exit
3: exit R without saving workspace
4: exit R saving workspace
Selection

Is it possible to use Oracle Wallet for node connection to its vault?

Is it possible to start an enterprise node, using an Oracle 12c backed up
vault configured via Oracle Wallet (i.e., configure the node.conf using only a
dataSource.url="jdbc:oracle:thin:#host:port:#SOME_ORACLE_WALLET_TNS" without
specifying any dataSource.username or dataSource.password parameters ) ?
In this case, please inform which additional oracle .jar files should be
added to the node drivers dir.
Oracle wallet is supported in Corda Enterprise. Below is a working configuration with Oracle Wallet, and has been tested with Oracle 11g and Oracle 12c.
Prerequisites
Oracle wallet is configured with auto login (-auto_login_local) for the node's database
Assuming that the node's database connection URL is configured in tnsnames.ora, with alias "db11g":
$ echo 'For JDBC URL ==> "jdbc:oracle:thin:#localhost:1521/xe" ==> below is an example of tnsnames.ora'
$ cat ~/oracle_experiment/tnsnames.ora
db11g =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = xe)
)
)
Wallet location is configured in sqlnet.ora:
$ cat ~/oracle_experiment/sqlnet.ora
WALLET_LOCATION =
(SOURCE =
(METHOD = FILE)
(METHOD_DATA =
(DIRECTORY = /Users/corda/oracle_wallet/)
)
)
SQLNET.WALLET_OVERRIDE = TRUE
SSL_CLIENT_AUTHENTICATION = FALSE
SSL_VERSION = 0
Sqlplus should be able to login without a password challenge:
sqlplus /#db11g
SQL*Plus: Release 12.2.0.1.0 Production on Tue Nov 27 15:17:00 2018
Copyright (c) 1982, 2017, Oracle. All rights reserved.
Last Successful login time: Tue Nov 27 2018 14:46:09 +08:00
Connected to:
Oracle Database 12c Standard Edition Release 12.1.0.2.0 - 64bit Production
SQL>
Necessary steps
Change the database-specific configuration from:
$ cat dbconfig_oracle11g.conf
dataSourceProperties = {
dataSourceClassName = "oracle.jdbc.pool.OracleDataSource"
dataSource.url = "jdbc:oracle:thin:#localhost:1521/xe"
dataSource.user = corda_es_user
dataSource.password = corda_es_passwd
}
To
$ cat dbconfig_oracle_wallet.conf
dataSourceProperties = {
dataSourceClassName = "oracle.jdbc.pool.OracleDataSource"
dataSource.url = "jdbc:oracle:thin:/#db11g"
dataSource.user=null
dataSource.password=null // user and password can't be ignored and can't be left blank.
}
Download and copy the following JARs into the node's drivers folder:
]$ ls <corda>/drivers/
ojdbc8.jar
osdt_cert.jar
osdt_core.jar
oraclepki.jar
Start the node with the oracle.net.wallet_location and oracle.net.tns_admin options:
]$ java -Doracle.net.wallet_location=/Users/corda/oracle_wallet/ -Doracle.net.tns_admin=/Users/corda/oracle_experiment/ -jar corda.jar
Refer to the SSL with JDBC blog for more details.

FreePBX 2.10 odbc storage

I would like to store voicemessages over odbc to mysql database.
Is app_voicemail compiled with odbc storage support?
This question cause setup in:
- "FreePBX 2.11" ask me to enable file-storage or odbc-storage'
- "FreePBX 2.10" same question is not asked.
Maybe cause support only 'file-storage'?
When i leave a message in vocalmail, in the log there is no trace of 'sql insert'.
In all examples that I've seen, where is the sql statement to insert in the table the row of voicemessage?
ODBC DSN Settings
-----------------
Name: asterisk
DSN: asterisk-connector
Last connection attempt: 1970-01-01 01:00:00
Pooled: No
Connected: Yes
-----------------
root#pbx:~ $ isql asterisk root passw0rd
+---------------------------------------+
| Connected! |
| |
| sql-statement |
| help [tablename] |
| quit |
| |
+---------------------------------------+
SQL>
-----------------
/etc/asterisk/func_odbc.conf
[SQL]
dsn=asterisk-connector
readsql=${ARG1}
-----------------
/etc/asterisk/res_odbc.conf
[asterisk]
enabled => yes
dsn => asterisk-connector
username => root
password => passw0rd
pooling => no
limit => 1
pre-connect => yes
-----------------
/etc/odbc.ini
[asterisk-connector]
Driver = MySQL
Description = MySQL connection to .asterisk. database
Server = localhost
Port = 3306
User = root
Password = --------
Database = asterisk
Option = 3
Socket = /var/lib/mysql/mysql.sock
-----------------
/etc/asterisk/voicemail.conf
odbcstorage=asterisk
odbctable=voicemessages
-----------------
ODBC storage depend from asterisk module. Asterisk have be compiled with voicemail-odbc enabled
It have very small relation with freepbx web. It should work if module present and configured.

How to send application_name to RPostgreSQL connection

I know that PostgreSQL database allows to keep track of application name for each connection and it looks like application_name variable should work with RPostgreSQL, but how exactly should I do this? Adding variable application_name = "test" to dbConnect doesn't work.
I'm not sure you can pass application_name='test' as an argument to dbConnect in RPostgreSQL (there is an optional options argument, but I couldn't figure out what kind of data it expects).
An alternative would be to run the following SQL query immediately after opening the connection:
SET application_name='test'
and it should work until you close the connection.
It's not well documented but something like this works:
drv <- dbDriver("PostgreSQL")
con <- dbConnect(drv,
dbname = "<my_db>",
host = "<my_host>",
[...],
options = "-c application_name=my_app_name"
)
It works with dbPool too (package 'pool'):
pool <- dbPool(
drv = dbDriver("PostgreSQL"),
dbname = "<my_db>",
host = "<my_host>",
[...]
minSize = 0,
maxSize = 3,
options = "-c application_name=my_app_name"
)
Check with pg_stat_activity
mydb=> SELECT state, usename, application_name FROM pg_stat_activity WHERE datname = 'mydb';
state | usename | application_name
--------+----------+------------------
active | postgres | psql
idle | myuser | my_app_name

Resources