R teradata DBI:dbConnect() error: TimedOut: No response received when attempting to connect to the Teradata server - r

I am going to ask and answer this question because I spent more time than I'd like to admit searching for a response and couldn't find one. I installed Teradata ODBC Driver 16.20. In the ODBC Data Source Administrator, I added a Data Source. I named it teradata, put in the name of the Teradata Server to connect to and my username and password for authentication. When I tried running the following code in RStudio:
con <- DBI::dbConnect(odbc::odbc(),
"teradata")
I would get an error:
Error: nanodbc/nanodbc.cpp:1021: HY000: [Teradata][WSock32 DLL] (434) WSA E TimedOut: No response received when attempting to connect to the Teradata server

To solve this, I needed to pass a timeout argument:
con <- DBI::dbConnect(odbc::odbc(),
"teradata",
timeout = 20)

Related

Unable to query Azure SQL Server from RStudio

I am trying to query an SQL Server database deployed on Azure from RStudio.
I established a connection. I can see all of the tables and get a preview of the data from the RStudio GUI. However, when I try to query the data I get an error.
library(dplyr)
library(odbc)
con <- dbConnect(odbc(),
Driver = "SQL Server",
Server = "#.database.windows.net",
Database = "loremipsum",
UID = "loremipsum",
PWD = "loremipsum",
Port = 1433)
First query I tried:
users <- as.data.frame(sqlQuery(con, "SELECT * FROM AspNetUsers"))
The error I got:
Error in sqlQuery(con, "SELECT * FROM AspNetUsers") :
first argument is not an open RODBC channel
I also tried this query
result <- dbSendQuery(con, "SELECT * FROM AspNetUsers")
first_100 <- dbFetch(result, n = 100)
With the following error:
Error in result_fetch(res#ptr, n) :
nanodbc/nanodbc.cpp:2966: 07009: [Microsoft][ODBC SQL Server Driver]Invalid Descriptor Index
It strange because the connection must be valid, given that it gets access to the data through the GUI.
Any hints?
Congratulations you have solved the issue:
I eventually solved the issue by switching to another libary - RODBC. It seems that thats a bug in the way odbc handles character columns as point:R DBI ODBC error: nanodbc/nanodbc.cpp:3110: 07009: [Microsoft][ODBC Driver 13 for SQL Server]Invalid Descriptor Index
I post this as answer and this can be beneficial to other community members.

R ODBC nanodbc error when not using DSN

Running into an issue between using the DSN versus non DSN with the R package ODBC.
Using the DSN, I am successfully able to make a connection to the server and away the code goes. However, using the non DSN odbc connection string, I am receiving:
Error: nanodbc/nanodbc.cpp:950: IM002: [Microsoft][ODBC Driver Manager] Data >source name not found and no default driver specified
The connection appears to be syntactically correct and all of the required fields are populated according to multiple function documentations, including: https://support.rstudio.com/hc/en-us/articles/214510788-Setting-up-R-to-connect-to-SQL-Server-
odbc_con <- dbConnect(odbc::odbc(),
Driver = "SQLServer",
Server = server,
Database = test,
Uid = 'username',
Pwd = 'password',
Port = 1433)
Both server and test are defined earlier in the code.
I have tried removing the odbc:: and just using odbc().
Using semi-colons, removing caps.
Bit stuck, any suggestions?
When I switched from a Linux to a Windows box for R (note nothing else changed) I was getting
"Error: nanodbc/nanodbc.cpp:950: IM002: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified"
The ODBC connection issue was fixed by changing
Driver = "ODBC Driver 17 for SQL Server"
to
Driver = "SQL Server"
Hope this saves you some time.

Problems with connection to Oracle from R

I want to connnect to Oracle with R. I use RODBC package for this connection. Following is my code to connect
library(RODBC)
con <- odbcDriverConnect("Driver={Microsoft ODBC for Oracle};
CONNECTSTRING=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=123)(PORT=1521))(CONNECT_DATA=(SID=abc)));
uid=abc; pwd=abc;")
But I get the following error
1:
[RODBC] ERROR: state IM002, code 0, message [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
2:
ODBC connection failed
It's really strange, because I use direct connection, it doesn't require no TSN nor DSN. Also I succesfully connect to Oracle with the same Hostname, Port, SID, Username and password, using Oracle SQL Developer.

pyodbc cannot connect whereas similar connection works with RODBC

I try to connect to my DB with the following request:
import pyodbc
connectionString = "driver={Adaptive Server Enterprise};database=#DB#;Server=#Server#;port=#port#;UID=#UID#;PWD=#PWD#;"
pyodbc.connect(connectionString)
However I get the following error, as if my connection string is not correct:
Error: ('IM002', '[IM002] [Microsoft][ODBC Driver Manager] Data source
name not found and no default driver specified (0)
(SQLDriverConnect)')
Which is strange, since I managed to connect to my DB in R with ROBC module.
library(RODBC)
ch = odbcDriverConnect(connection = connectionString)
Any idea what is wrong with my connection string in pyodbc ?
I resolved my problem, the request is working with 32-bits python interpreter.
It appears not to be 64bits compatible.
Similar topic here: cannot connect to 64bit MsAccess database with 64bit Python 3.6.ODBC Driver Error

Connect R and Vertica using RODBC

This is my first time connecting to Vertica. I have already connected to a MySQL database sucessfully by using RODBC library.
I have the database setup in vertica and I installed the windows 64-bit ODBC driver from https://my.vertica.com/download-community-edition/
When I tried to connect to vertica using R, I get the below error:
channel = odbcDriverConnect(connection = "Server=myserver.edu;Database=mydb;User=mydb;Password=password")
Warning messages:
1: In odbcDriverConnect(connection = "Server=myserver.edu;Database=mydb;User=mydb;Password=password") :
[RODBC] ERROR: state IM002, code 0, message [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
2: In odbcDriverConnect(connection = "Server=myserver.edu;Database=mydb;User=mydb;Password=password") :
ODBC connection failed
Can someone tell me how to fix this? Or is there any other ways to connect to vertica using R?
It may not be the fastest, but I prefer to use the Vertica JDBC driver from R. Getting the ODBC drivers working is a little messy across different operating systems. If you already have a Java Runtime Environment (JRE) installed for other applications then this is fairly straightforward.
Download the Vertica JDBC drivers for your Vertica server version from the MyVertica portal. Place the driver (a .jar file) in a reasonable location for your operating system.
Install RJDBC into your workspace:
install.packages("RJDBC",dep=TRUE)
In your R script, load the RJDBC module and create an instance of the Vertica driver, adjusting the classPath argument to point to the location and filename of the driver you downloaded:
library(RJDBC)
vDriver <- JDBC(driverClass="com.vertica.jdbc.Driver", classPath="full\path\to\driver\vertica_jdbc_VERSION.jar")
Make a new connection using the driver object, substituting your connection details for the host, username and password:
vertica <- dbConnect(vDriver, "jdbc:vertica://host:5433/db", "username", "password")
Then run your SQL queries:
myframe = dbGetQuery(vertica, "select Address,City,State,ZipCode from MyTable")
You have to use double slash in the classPath arguement in JDBC function.
for example,
vDriver <- JDBC(driverClass="com.vertica.jdbc.Driver",
classPath="C:\\Program Files\\Vertica Systems\\JDBC\\vertica-jdk5-6.1.2-0.jar")
worked for me, while just copying and pasting the route failed.

Resources