RODBC Connection Failed Cant Find Server - r

I am attempting to connect my local SQL server/database to Power BI through R using odbc.
I have been looking around online at many threads to try to find a solution. Other people have had my issue, but the solutions they were provided are not working for me. I'm sure this is simple, I just can't get it.
ch <- odbcDriverConnect(
"Driver={SQL Server};Server=localhost;Database=deliverydashboard;Trusted_Connection=TRUE"
)
These are the error messages I receive:
1: In odbcDriverConnect("Driver={SQL Server};Server=localhost;Database=deliverydashboard;Trusted_Connection=TRUE") :
[RODBC] ERROR: state 08001, code 17, message [Microsoft][ODBC SQL Server Driver][DBNETLIB]SQL Server does not exist or access denied.
2: In odbcDriverConnect("Driver={SQL Server};Server=localhost;Database=deliverydashboard;Trusted_Connection=TRUE") :
[RODBC] ERROR: state 01000, code 2, message [Microsoft][ODBC SQL Server Driver][DBNETLIB]ConnectionOpen (Connect()).
3: In odbcDriverConnect("Driver={SQL Server};Server=localhost;Database=deliverydashboard;Trusted_Connection=TRUE") :
ODBC connection failed
Error in sqlQuery(ch, "DROP TABLE deliveryexpensebackend") :
first argument is not an open RODBC channel
Execution halted

Related

Connect to Oracle DB instance using R

I try to connect to an oracle DB using Rstudio, but I can't figure out how to do it. I have connected to the database with PowerBi, so I know it is accessible (from my pc/ip) and that the database works fine, however using R I cannot get this done. Prior to asking this question I have been searching the web for days, I'm not new to R or SQL, but I am to Oracle. I have tried various packages (DBI, odbc, RODBC etc.) but still no success.
I have talked to the administrators of the DB, they said I should be able to connect using the following information which is provided to me;
Server: xxx.xxx.xx.xx
Port : xxxx
Instance : ORCL
User: myusername
Pwd : mypwd
When I connect to the DB using PowerBI, my server name is: server/instance, in combination with the uid and pwd the connection than works fine.
The closest I (think I) got, was using the 'odbcDriverConnect()' function.
First I ran the following command to check which drivers are installed;
sort(unique(odbcListDrivers()[[1]]))
which gave as output
"Oracle in OraClient12Home1" "Oracle in OraClient12Home2" "SQL Server"
Other topics here on stackoverflow, suggested the following site to check which string to use in the function:
https://www.connectionstrings.com/oracle/
I couldn't find a specific one for my listed drivers, but I altered the one for the Oracle in OraClient11g_home1 since it seemed to be the best match, this string is as follows;
Driver={Oracle in OraClient11g_home1};Server=serverSID;Uid=myUsername; Pwd=myPassword;
So I replaced the Oracle in OraClient11g_home1 with my drivers, they all gave another error;
con <- odbcDriverConnect("Driver={Oracle in OraClient12Home1};Server=xxx.xxx.xx.xx/orcl;Uid=xxx;Pwd=xxx;")
Warning messages:
1: In odbcDriverConnect("Driver={Oracle in OraClient12Home1};Server=xxx.xxx.xx.xx/orcl;Uid=xxx;Pwd=xxx;") :
[RODBC] ERROR: state IM003, code 160, message Het opgegeven stuurprogramma kan niet worden geladen vanwege een systeemfout 126: Kan opgegeven module niet vinden. (Oracle in OraClient12Home1, C:\Program Files\Oracle\product\12.2.0\client_1\SQORA32.DLL).
2: In odbcDriverConnect("Driver={Oracle in OraClient12Home1};Server=xxx.xxx.xx.xx/orcl;Uid=xxx;Pwd=xxx;") :
ODBC connection failed
The error is in Dutch, stating that the driver cannot be found due to systemerror 126
the next driver gives another error;
con <- odbcDriverConnect("Driver={Oracle in OraClient12Home2};Server=xxx.xxx.xx.xx/orcl;Uid=xxx;Pwd=xxx;")
Warning messages:
1: In odbcDriverConnect("Driver={Oracle in OraClient12Home2};Server=xxx.xxx.xx.xx/orcl;Uid=xxx;Pwd=xxx;") :
[RODBC] ERROR: state HY000, code 12560, message [Oracle][ODBC][Ora]ORA-12560: TNS:protocol adapter error
2: In odbcDriverConnect("Driver={Oracle in OraClient12Home2};Server=xxx.xxx.xx.xx/orcl;Uid=xxx;Pwd=xxx;") :
ODBC connection failed
The last driver, is the only one who takes a few seconds, suggesting its actually trying to connect, but eventually also gives an (other) error;
con <- odbcDriverConnect("Driver={SQL Server};Server=xxx.xxx.xx.xx/orcl;Uid=xxx;Pwd=xxx;")
Warning messages:
1: In odbcDriverConnect("Driver={SQL Server};Server=xxx.xxx.xx.xx/orcl;Uid=xxx;Pwd=xxx;") :
[RODBC] ERROR: state 08001, code 17, message [Microsoft][ODBC SQL Server Driver][DBNETLIB]De SQL-server bestaat niet of de toegang tot de server is geweigerd.
2: In odbcDriverConnect("Driver={SQL Server};Server=xxx.xxx.xx.xx/orcl;Uid=xxx;Pwd=xxx;") :
[RODBC] ERROR: state 01000, code 53, message [Microsoft][ODBC SQL Server Driver][DBNETLIB]ConnectionOpen (Connect()).
3: In odbcDriverConnect("Driver={SQL Server};Server=xxx.xxx.xx.xx/orcl;Uid=xxx;Pwd=xxx;") :
Stating that the server doesn't exists or that the acces is denied. Once again, I know it exists and that I am granted access because it works on powerBi, so I am kind off lost right now. I have tried the server with and without the /orcl. If anyone has any clue on what I am missing that would be greatly appreciated!
Kind regards
With instant client and ipaddress of server
con <- odbcDriverConnect("Driver={Oracle in OraClient12Home2};Dbq=server_ipaddress:1521/orcl;Uid=xxx;Pwd=xxx;")
or if you can ping server
con <- odbcDriverConnect("Driver={Oracle in OraClient12Home2};Dbq=server:1521/orcl;Uid=xxx;Pwd=xxx;")
Other option if you have tnsnames.ora in instant client home and set tns_admin variable you can use service name in tnsnames.ora file
con <- odbcDriverConnect("Driver={Oracle in OraClient12Home2};Dbq=orcl;Uid=xxx;Pwd=xxx;")
P.S:-I never worked on R just downloaded R and R studio

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.

Error in connecting R to Oracle database using RODBC

I am trying to connect R to an Oracle database. I am getting an error which I have already tried to trouble shoot but not able to find a solution.
I created a DSN and successfully tested the connection
I then tried to establish a connection in R.
con <- odbcConnect("DSNNAME", uid='ID', pwd='PWD')
But I receive an error.
Warning messages:
1: In RODBC::odbcDriverConnect("DSN=DSNNAME;UID=ID;PWD=PWD") :
[RODBC] ERROR: state IM014, code 0, message [Microsoft][ODBC Driver Manager]
The specified DSN contains an architecture mismatch between the Driver and Application
2: In RODBC::odbcDriverConnect("DSN=DSNNAME;UID=ID;PWD=PWD") :
ODBC connection failed
I have replaced my id and password with dummies.
Also I am using 64 bit R.

Could open accdb database (MS Access) from R and now I can't

I have a little R code that was working perfectly well until a few days ago and now, all of a sudden, it works on some PCs and it doesn't in others. Does anybody know if any update has been pushed by MS that could be causing the trouble?
I'm running R-32bit in all PCs and the ones not working seem to have upgraded MS Access 2010 to 2016.
This is my code:
library(RODBC)
testdb <- file.path("foo.accdb")
channel <- odbcConnectAccess2007(testdb)
tables_list=grep("foo_table", sqlTables(channel)[,3], value=TRUE) # list of tables with matching names
odbcCloseAll()
The error message I get is:
Error in sqlTables(channel) : first argument is not an open RODBC
channel
In addition: Warning messages: 1: In odbcDriverConnect(con, ...) :
[RODBC] ERROR: state IM002, code 0, message [Microsoft][ODBC Driver
Manager] Data source name not found and no default driver specified 2:
In odbcDriverConnect(con, ...) : ODBC connection failed
Mystery solved! Apparently the upgrade to MS Access 2016 deleted the 32-bit drivers for ODBC. Reinstalling the Microsoft Access Database Engine 2010 32-bit got things to work again.
Thanks to all for your help!

Query MS Access DB from R with 64-bit Windows

Someone asked me to create a Shiny UI to allow them to read and write from their Microsoft Access database, created with MS Office 2010.
I was following this guide to connect to the Access DB with RODBC and -- while I can open this database in Access itself -- I get the following error from R:
> channel <- odbcConnectAccess("AD_Users.accdb")
Error in odbcConnectAccess("AD_Users.accdb") : `
odbcConnectAccess is only usable with 32-bit Windows
So, I found this solution and gave it a try:
> channel <- odbcDriverConnect("AD_Users.accdb")
Warning messages:
1: In odbcDriverConnect("AD_Users.accdb") :
[RODBC] ERROR: state IM002, code 0, message [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
2: In odbcDriverConnect("AD_Users.accdb") :
[RODBC] ERROR: state 01S00, code 0, message [Microsoft][ODBC Driver Manager] Invalid connection string attribute
3: In odbcDriverConnect("AD_Users.accdb") : ODBC connection failed
> channel <- odbcDriverConnect("Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=AD_Users.accdb")
Warning messages:
1: In odbcDriverConnect("Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=AD_Users.accdb") :
[RODBC] ERROR: state IM002, code 0, message [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
2: In odbcDriverConnect("Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=AD_Users.accdb") :
ODBC connection failed
>
but as you can see, there were some pretty serious warnings. It doesn't seem to work.
Is there any other work-around?
I am using 32-bit R when I receive these warnings and even though they're warnings and not technically errors, the database connection is unsuccessful.
Update
This seems to establish a successful connection, though I've been unable to query data from it thusfar:
channel <- odbcConnectDbase("AD_Users.accdb")
I use odbcConnectAccess2007 in RODBC and don't have any issues connecting to Access databases when using 64-bit windows. However, you should check the package manual (link to pdf) to make sure that you have the appropriate drivers installed on your computer. Once you have the right drivers you should be good to go!

Resources