ODBC error running R script in cmd window - r

This is a follow-up question to:
Error in running R script in cmd window
I am still getting errors, but I switched from 64bit to 32bit R, and I think I am closer now, so I was hoping the following would jog someone's memory or tinfoil :)
Anyway, the paradox is that the following code runs instantly INSIDE of R :
library(RODBC)
myconn <- odbcConnect("****", uid = "*******", pwd = "*******")
test <- sqlQuery(myconn, "select * from tableAXd")
close(myconn)
summary(test)
But the very same code (in bat_test.R), sourced from a .bat file with this code:
C:\Users\********\Documents\R\R-3.3.1\bin\Rscript.exe "C:\schedule\bat_test.R"
generates the following error in the cmd window:
[RODBC] ERROR: state IM104, code 0, message [Microsoft][ODBC Driver Manager] The specified DSN contains an architecture mismatch between the Driver and the Application...
So, why would the exact same code run sweetly from R, but choke on ODBC from a .bat file?
Thanks for listening...
isotope

Related

RODBC connection works in RStudio but not in prompt, stuck with architecture incompatibility issue

I'm trying to exec a R script with a prompt command but I'm struggling with compatibility issues and I can't find the proper way to achieve this.
I'm on Windows x64, I have a x32 DSN that works perfectly when the R script is executed in x64 RStudio (with R x32 by default).
Then I tried to execute this script with System32\cmd.exe like this
C:\Users\Me\Documents\R\R-4.1.1\bin\Rscript.exe "C:\Documents\Script.R"
But I get an error
[Microsoft][ODBC Driver Manager] The specified DSN contains an architecture mismatch between the Driver and Application
I'v tried to :
Use SysWOW64\cmd.exe AND bin\x64\Rscript.exe, same error
Use System32\cmd.exe AND bin\x64\Rscript.exe, same error
Use SysWOW64\cmd.exe AND bin\Rscript.exe, same error
Use System32\cmd.exe AND bin\Rscript.exe, same error --> I thought this one would work
There must be something that I don't get...
EDIT: As r2evans suggested, here is the script i'm trying to run with a promp command. I reduced it to the connecting part, the rest is just basic SQL Query
##################################### PACKAGES ################################
#******************************************************************************
# List of needed packages
list.of.packages <- c("RODBC", "dplyr","stringr","lubridate", "readr","openxlsx","readxl","RMySQL","data.table")
# Find not installed
new.packages <- list.of.packages[!(list.of.packages %in% installed.packages()[,"Package"])]
# Install packages
if(length(new.packages)) install.packages(new.packages)
# Load packages
lapply(list.of.packages, library, character.only=T)
library("RMySQL")
library(utf8)
rm(list.of.packages,new.packages)
connexion <- odbcConnect (dsn = "MYDSN", uid = "LOGIN", pwd = "PASSWORD")

R Code works fine in RStudio but not in terminal - ODBC SQL - Failed to load the security library: (libgssapi_krb5.dylib)

I have some R code made in RStudio. It connects to SQL-Server, runs a query and saves out a csv.
It runs fine in RStudio but i want it to run in terminal so I can schedule it daily.
I have tried googling the error message for I can't seem to find what im looking for.
The SQL server authenticates with Windows Auth. Therefor im not suppling a username and password.
library(odbc)
con <- dbConnect(odbc::odbc(),.connection_string = "Driver={Simba SQL Server ODBC Driver};
Server=MYSERVER;
Database=TEST;
trusted_connection=true")
This is the error message I'm getting:
Error: nanodbc/nanodbc.cpp:950: HY000: [Simba][Support] (50366) Failed to load the security library: (libgssapi_krb5.dylib)
Execution halted
I'm really new to R so I'm not too sure whats happening, any help would be really appreciated.
Thanks!

Error When Running Data Function With "Force Server" On Run Location

I'm having a constant error whenever I try to execute my data function forcing it to run on Spotfire Server.
The script works fine on R Studio and also on Spotfire if the Run Location configuration is set to "Force Local" or "Default".
When I use the Force Server, I get the following error message when executing a query:
Could not execute function call. TIBCO Spotfire Statistics Services returned an error:
'Error in sqlQuery(myconn, mappingQuery, errors = TRUE, rows_at_time = : first argument is not an open RODBC channel'.
at Spotfire.Dxp.Data.DataFunctions.Executors.RemoteFunctionClient.OnExecuting(FunctionClient funcClient)
at Spotfire.Dxp.Data.DataFunctions.Executors.AbstractFunctionClient.<RunFunction>d__0.MoveNext()
at Spotfire.Dxp.Data.DataFunctions.Executors.SPlusFunctionExecutor.<ExecuteFunction>d__0.MoveNext()
at Spotfire.Dxp.Data.DataFunctions.DataFunctionExecutorService.<ExecuteFunction>d__6.MoveNext()
Even if I have a straightforward script and query like the one below, the results are the same:
require(RODBC)
myconn <- odbcDriverConnect("Driver={SQL Server};Server=MY_SERVER;Database=MY_DATABASE;Trusted_Connection=True")
# myconn <- odbcDriverConnect("Driver={SQL Server};Server=MY_SERVER;Database=MY_DATABASE;UID=MY_USER;Pwd=MY_PASSWORD") ## Same result with trusted connection or user/password
query <- "SELECT * FROM MY_TABLE"
df <- sqlQuery(myconn, query)
print(df)
Have anyone ever seen this?
Thanks!
The error seems to suggest that the "RODBC" package's 'odbcDriverConnect()' function might not be finding the ODBC drivers it needs on the server that TIBCO Spotfire Statistics Services (TSSS) is installed on.
Try installing the required odbc drivers on the machine where the TIBCO Spotfire Statistics Services is installed.

Connect Oracle DB through RStudio using RODBC

I might be re-asking the question but I am having difficulty creating connection to Oracle DB which is on a remote server. I am new to R and Oracle DB so I do not have much experience. I am using RStudio. I have installed RODBC package successfully. I am using Ubuntu 14.04 Operating System.
Firstly I use library RODBC
library("RODBC", lib.loc="~/R/x86_64-pc-linux-gnu-library/3.0")
Then I have entered following command:
odbcConnect(dsn = "DatabaseName", uid = "UserID", pwd = "Password")
I get the following error:
[1] -1
Warning messages:
1: In RODBC::odbcDriverConnect("DSN=DatabaseName;UID=UserID;PWD=Password") :
[RODBC] ERROR: state IM002, code 0, message [unixODBC][Driver Manager]Data source name not found, and no default driver specified
2: In RODBC::odbcDriverConnect("DSN=DatabaseName;UID=UserID;PWD=Password") :
ODBC connection failed
I have searched but I am not getting to anywhere. Please tell me process or steps to how I can make a connection.
Thank You!

Trouble with using RODBC to access Northwind.accdb file

I'm trying to demo SQL queries from within R using the Northwind.accdb file. I visited http://office.microsoft.com/en-us/templates/desktop-northwind-2007-sample-database-TC001228997.aspx and was able to download the .accdt file. I've tried creating a database connection using RODBC with the following two lines, but both return the same error that R is unable to find the file, even though I am certain of its location (on the desktop).
Here are the lines of code that I'm using:
conn <- odbcConnectAccess2007("Nwind.accdt", uid = "", pwd = "")
conn <- odbcConnectAccess2007("Nwind.accdb", uid = "", pwd = "")
The error output I'm getting looks like this:
Warning messages:
1: In odbcDriverConnect(con, ...) :
[RODBC] ERROR: Could not SQLDriverConnect
2: In odbcDriverConnect(con, ...) : ODBC connection failed
Very grateful for any pointers you all might have.
There are some problems when using 32 bit drivers on 64 bit Windows. If you have ODBC 32 bit installed, coming with older versions of Office, make sure that you are running 32-bit R (easy with RStudio under Tools).
Or, with 64 bit drivers, use 64 bit R.

Resources