I am trying to connect to Teradata database from R terminal using code below,
"> con <- DBI::dbConnect(odbc::odbc(),
+ Driver = "Teradata",
+ Host = "xxxx",
+ DBCName = "xxxx",
+ UID = "xxxx"
+ )"
I have created /etc/odbc.ini and /etc/odbcinst.ini and below are the contents of the same,
odbc.ini:
[ODBC]
InstallDir=/opt/teradata/client/16.20/odbc_64
DataEncryption='ON'
[ngmtdd01]
Driver=/opt/teradata/client/16.20/odbc_64/lib/tdataodbc_sb64.so
Description=Teradata Dev
DBCName=xxxx.dev.uk.capitalone.com
LoginTimeout=120
odbcinst.ini
[ODBC DRIVERS]
Teradata Database ODBC Driver 16.20=Installed
[Teradata Database ODBC Driver 16.20]
Driver=/opt/teradata/client/16.20/odbc_64/lib/tdataodbc_sb64.so
APILevel=CORE
ConnectFunctions=YYY
DriverODBCVer=3.51
SQLLevel=1
I expected to get connected to the teradata cli but I am getting below error.
Error: nanodbc/nanodbc.cpp:950: IM002: [DataDirect][ODBC lib] Data source name not found and no default driver specified"
You defined a DSN but your connection string is "DSN-less" (using Driver= not DSN=) and Driver= specifies the wrong driver name; the actual name is Teradata Database ODBC Driver 16.20
Note that Teradata also supplies a Teradata SQL Driver for R package that does not require ODBC.
Related
Disclaimer: I'm a statistician/bioinformatician by training, so I'm quite new to networks, servers, and databases.
System: Macbook Pro (M1 chip).
I'm trying to connect to an SQL Server database remotely via R and RStudio.
To start, I ran the following commands in terminal (as seen here https://learn.microsoft.com/en-us/sql/connect/odbc/linux-mac/install-microsoft-odbc-driver-sql-server-macos?view=sql-server-ver16):
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
brew tap microsoft/mssql-release https://github.com/Microsoft/homebrew-mssql-release
brew update
HOMEBREW_NO_ENV_FILTERING=1 ACCEPT_EULA=Y brew install msodbcsql18 mssql-tools18
The code I'm running in RStudio is as follows (as seen here https://db.rstudio.com/getting-started/connect-to-database):
library(DBI)
library(odbc)
con <- DBI::dbConnect(odbc::odbc(),
Driver = "ODBC Driver 18 for SQL Server",
Server = "xxx.xxx.xxx.xx",
Database = "Dbname",
UID = "username",
PWD = "password",
Port = 3306,
.connection_string ="TrustServerCertificate=yes")
The above gives me the following error:
Error: nanodbc/nanodbc.cpp:1021: 00000: [unixODBC][Driver Manager]Data
source name not found and no default driver specified
I can't find any help related to the errors I'm getting at https://db.rstudio.com/getting-started.
Slightly different piece of code gives me a different error:
con <- DBI::dbConnect(odbc::odbc(),
.connection_string = "Driver={ODBC Driver 18 for SQL
Server};Uid=username;Pwd=password;Host=xxx.xxx.xxx.xx;Port=3306;Database=Dbname;TrustServerCertificate=yes;")
Error: nanodbc/nanodbc.cpp:1021: 00000: [Microsoft][ODBC Driver 18 for
SQL Server]Neither DSN nor SERVER keyword supplied [Microsoft][ODBC
Driver 18 for SQL Server]Invalid connection string attribute
What is a Server Keyword as referred to in the second error? Is the server supposed to be an IP address as I've indicated in the code?
Does the use of ODBC Driver matter? How can I tell if I'm using the right one?
Am I off the mark with any of the information I'm feeding into dbConnect()?
Any tips welcome.
Thanks.
Thanks to #AlwaysLearning for pointing at the mistake in my second chunk of code. Host= should have been Server=.
As for the first chunk, I don't know why it wouldn't work.
I'm trying to connect to AWS Athena using Simba Athena ODBC in r.
DBI::dbConnect(
odbc::odbc(),
driver = "Simba Athena ODBC Driver",
S3OutputLocation = <>,
AwsRegion = "us-east-2",
AuthenticationType = "IAM Credentials",
Schema = <>,
AWS_ACCESS_KEY_ID = <>,
AWS_SECRET_ACCESS_KEY = <>)
Error: nanodbc/nanodbc.cpp:1021: 00000: [Simba][ODBC] (11560) Unable to locate SQLGetPrivateProfileString function: [Simba][DSI] An error occurred while attempting to retrieve the error message for key 'LibsLoadErr' with message parameters ['""'] and component ID 3: Message not found in file "/Library/simba/athenaodbc/ErrorMessages/en-US/ODBCMessages.xml"
I've updated my ODBC driver to route to the correct file per this question - Simba Athena ODBC: unable to use SQLGetPrivateProfileString functions
I am also getting a response from the odbc:odbcListDrivers() function:
name attribute value
ODBC Drivers Simba Athena ODBC Driver Installed
Simba Athena ODBC Driver Description. Simba Athena ODBC Driver
Simba Athena ODBC Driver Driver. /Library/simba/athenaodbc/lib/libathenaodbc_sb64.dylib
I am trying to connect to a MySQL database from within R using odbc. If I write the connection information it works well, however, if I put the same information in a odbc.ini file, I get an error.
Here is the code that works
library(DBI)
con <- DBI::dbConnect(odbc::odbc(),
Driver = "MySQL ODBC 8.0 ANSI Driver",
Server = "localhost",
UID = "myname",
PWD = "mypassword",
Database = "vgr",
encoding = "latin1",
Port = 3306)
And here the code that doesn't work
con <- DBI::dbConnect(odbc::odbc(), 'MySQL')
The error is (it looks like dbConnect doesn't find the information):
Error: nanodbc/nanodbc.cpp:983: IM002: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
This is in my odbc.ini either in the working directory or where Windows saves it ODBC.ini file.
[MySQL]
Driver = MySQL ODBC 8.0 ANSI Driver
Server = localhost
UID = myname
PWD = mypassword
Database = vgr
encoding = latin1
Port = 3306
Any help would be appreciated.
Cheers
Renger
I am using both the DBI and ODBC package in "R" in order to make a connection to an ORACLE database.
Here is the connection code I am using:
library(DBI)
library(odbc)
con <- DBI::dbConnect(odbc::odbc(),
Driver = "ORACLE",
Host = "orasada.ca",
SVC = "STG",
UID = "username",
PWD = "password",
Port = 1521)
Everything looks fine to me, but I keep getting this error:
Error: nanodbc/nanodbc.cpp:983: IM002: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
Any ideas on what I can change to make a successful connection?
Thanks.
I am trying to connect R with Microsoft SQL server. I have used Toad for SQL Server 6.8 so far for my queries. However, for some other analysis (which can be easily performed in R) I want to connect database with R.
I have tried R function "dbconnect" with providing server name and database name. See query below:
odbc_con <- dbConnect(odbc::odbc(),
Driver = "SQL Server",
Server = "xxxxx",
Database = "yyyyy",
Uid = 'US\dhrdesai',
Pwd = rstudioapi::askForPassword("Database password"),
Port = 1433)
However, I got following errors:
Error: nanodbc/nanodbc.cpp:950: IM002: [Microsoft][ODBC Driver
Manager] Data source name not found and no default driver specified
and
Error: unexpected ')' in " Port = 1433)"
Have anyone faced the same or know any other way to connect R with SQL server.
You need to use a double backslash \\ every time you see a \. I just made my connection work yesterday with the following code. Also pehaps you have not installed all the packages that is required.
library(DBI)
library(dbplyr)
library(odbc)
con <- dbConnect(odbc::odbc(),
Driver = "SQL Server",
Server = "path\\path", # remember \\ if your path has a \
Database = "the_database_name",
user = "your_user_name", # remember \\ if your username has a \
Trusted_Connection = "True")