I am trying to connect to Snowflake with R:
library(DBI)
library(odbc)
con <- DBI::dbConnect(odbc::odbc(),
"SnowflakeDSII"
)
OR
con <- DBI::dbConnect(odbc::odbc(),
Driver = "Snowflake",
Server = "*.snowflakecomputing.com",
UID = "*",
PWD = "*",
Database = "*",
Warehouse = "*",
Schema = "PUBLIC"
)
But constantly get this error:
Error: nanodbc/nanodbc.cpp:1021: 00000: [unixODBC][Driver Manager]Can't open lib '/opt/snowflake/snowflakeodbc/lib/universal/libSnowflake.dylib' : file not found
I use iODBC Data Source Administrator to test the connection of DNS that I have setup and it says:
The connection DSN was tested successfully, and can be used at this time.
I am macOS Big Sur, Apple M1 chip with R 4.1.0
Update
content of the /Library/ODBC/odbcinst.ini:
[ODBC Drivers]
Snowflake = Installed
[Snowflake]
Driver = /opt/snowflake/snowflakeodbc/lib/universal/libSnowflake.dylib
Update 2
If I run the same script with Rscript under sudo, I get different error:
Error: nanodbc/nanodbc.cpp:1021: 00000: [unixODBC][Driver Manager]Data source name not found and no default driver specified
Execution halted
The issue is a reference issues with the drivers... the 64-bit driver was probably installed 2nd. I'd remove both drivers and only install one.
Related
I am trying to run some queries in Oracle SQL through R using RODBC but it doesn't work, not matter what I try.
I installed the "basic", "sqlplus", "odbc" and "sdk" packages from Oracle (yes, I know sdk and sqlplus aren't strictly needed), did all the path settings needed, copied libodbcinst.2.dylib to the instant client folder, installed the odbc driver in odbcinst.ini, tried changing dynlib locations through install_name_tool, even tried adding "arch -x86_64" before the driver name on odbcinst.ini - all to no avail.
I am using a MacBook Air M1, macOS Monterey 12.3.1, unixodbc installed on opt/homebrew from homebrew...
The connection string is:
sqlDriver <- 'Oracle 19 ODBC driver'
connectionStringSQL <- paste0(
"Driver=", sqlDriver,
";Server=", sqlServer,
";Database=", sqlDatabase,
";Uid=", sqlUser,
";Pwd=", sqlPassword,
";Encrypt=yes",
";Port=1521")
conn <- odbcDriverConnect(connectionStringSQL)
But I don't think the connection string matters, because the error I get is:
Warning messages:
1: In odbcDriverConnect(connectionStringSQL) :
[RODBC] ERROR: state 01000, code 0, message [unixODBC][Driver Manager]Can't open lib 'arch -x86_64 /Users/*****/instantclient/libsqora.dylib.19.1' : file not found
2: In odbcDriverConnect(connectionStringSQL) : ODBC connection failed
This worked perfectly for months. today I updated R and DBI library to 3.6.3 and now this..
library(DBI)
con <- dbConnect(odbc::odbc(), driver = Sys.getenv("DRIVER_PATH"),
server = "aus_net", database = "ice",
uid = Sys.getenv("USERNAME"), pwd = Sys.getenv("PASSWORD"))
Error: nanodbc/nanodbc.cpp:983: 00000: [unixODBC][Driver Manager]
Can't open lib '/Applications/IBM/informix/lib/cli/iclit09b.dylib' : file not found
yet
system("ls /Applications/IBM/informix/lib/cli/")
# [1] iclit09b.dylib
Any ideas?
What I know so far
After tracing some of the code, I see dbConnect() calls an internal function from odbc (odbc:::OdbcConnection)
i created a more detailed issue here
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.
I'm trying to connect R with an MS Access database on a Windows 7 64bit machine.
library(RODBC)
con <- odbcConnectAccess2007("M:/path/to/mydatabase/my.database.accdb")
# [RODBC] ERROR: state IM002, code 0, message [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specifiedODBC connection failed
I've also tried package odbc using connection strings specified at https://www.connectionstrings.com/access/ but similarly cannot connect
library(DBI)
con <- dbConnect(drv = odbc::odbc(), dsn = "Microsoft Access Driver", driver = "Microsoft Access Driver (*.mdb, *.accdb)", database = "M:/path/to/mydatabase/my.database.accdb")
# Error: nanodbc/nanodbc.cpp:950: IM002: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
What am I doing wrong?
You can use my AceOdbcCheck script to test your machine for a valid install of Access "ACE" ODBC. If you don't have it installed you can download the drivers here.
Note that the "bitness" (64-bit or 32-bit) of the Access ODBC driver must match the version of R you are running. That is, if you are running 32-bit R then you need the 32-bit drivers even though you are running 64-bit Windows.
I'm pretty new to R and may be I'm re-asking this question again, but I'm posting this as I didn't find an appropriate answer.
I'm trying to connect to Oracle DB that sits on a remote location from R using RODBC. I went through a lot of RODBC configuration documents but nothing clearly specifies connection to remote Oracle DB and what is the root cause.
I also pondered on using ROracle as DBI but found out that RODBC fares much better for multiple reasons.
So, here's my code:
> # Load RODBC package
> library(RODBC)
> # Create a connection to the database
> dbconnection <- odbcDriverConnect("Driver={Oracle ODBC Driver}; Server=my_hostname; Database=my_db_name; Uid=my_uid; Pwd=my_pwd")
> # Check that connection is working
> odbcGetInfo(dbconnection)
> close(dbconnection)
And the TNS Config that I use [values altered for obvious reasons]:
my_db_name =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = my_hostname)(PORT = my_port))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = my_service_name)
)
)
Note: The other thing here is that I don't have a local Oracle DB setup. I use SQL Developer to connect to the remote Oracle DB with the given TNS Config.
I get the below error:
Warning messages:
1: In odbcDriverConnect("Driver={Oracle ODBC Driver}; Server=my_hostname; Database=my_db_name; Uid=my_uid; Pwd=my_pwd") :
[RODBC] ERROR: state 01000, code 0, message [unixODBC][Driver Manager]Can't open lib 'Oracle ODBC Driver' : file not found
2: In odbcDriverConnect("Driver={Oracle ODBC Driver}; Server=my_hostname; Database=my_db_name; Uid=my_uid; Pwd=my_pwd") :
ODBC connection failed
After installing R, I have only installed RODBC using the install.packages("RODBC") command. Also, I'm running this on Mac OS.
I know I'm missing something here. Specifically the Driver={Oracle ODBC Driver} might need to modified to the actual drivers name. But I don't know what it should be and googling didn't help much.
Is there anything else that I need to install or configure?