I have an R Shiny script that works fine on my local windows computer, but fails when I deploy it to shinyapps.io (which is some unix like).
I originally used:
odbcConnectAccess('test.mdb') but when deployed, I get the follwing error:
Unhandled error in observer: could not find function "odbcConnectAccess"
I tested, and other RODBC functions still work. So I tried this code (based of this post, which also happens to be what the internals of odbcConnectAccess() return)
uid=""
pwd=""
con =paste("Driver={Microsoft Access Driver (*.mdb)};Dbq=", file.path(getwd(),'test.mdb'), ";Uid=", uid, ";Pwd=", pwd, ";", sep = "")
conn=odbcDriverConnect(con)
Again, this works on my local machine, but when deployed to ShinyApps.io I get the following error:
[RODBC] ERROR: state IM002, code 0, message [unixODBC][Driver Manager]Data source name not found, and no default driver specified
I also accidentally tried odbcConnect(con), which gives the following error:
Warning in odbcDriverConnect("DSN=Driver={Microsoft Access Driver (*.mdb)};Dbq=/srv/connect/apps/ALC_app_v0_1/Salvage_data_FTP.mdb;Uid=;Pwd=;") :
[RODBC] ERROR: state IM012, code 0, message [unixODBC][Driver Manager]DRIVER keyword syntax error
In the help for odbcDriverConnect() it mentions that the the format for the connection string depends on your ODBC, and Shinysapps.io seems to use unixODBC, but I cant find what format unixODBC wants me to use so that I can establish the connection?
Can anyone help me figure out how open a connection to a .mdb on shinyapps.io? I'm not sure If I'll be able to alter .ini files on shinyapps.io server, so I'm really hoping to find the correct format/syntax to establish the connection without a DSN.
Thanks for any help or feedback!
"...We currently only support open source databases on shinyapps.io, but we are watching to see if we get a lot more requests for proprietary databases."
From ShinyApps-User group. 10/23/2015
So it looks like the answer is NO currently. [UPDATE SEE BELOW]
Sorry to answer my own question, but I'm going to leave it up since it took me a while to find the confirmation, and it could save others some headache.
[UPDATE]
"Andy corrected me (while on vacation) and let me know that you can make this work by using the FreeTDS driver. I am not an expert on this, but if you change your code to something like this:
odbcDriverConnect("driver=FreeTDS;Server=hostname;database=dbname;uid=username;pwd=password")
We don't have any DSNs configured, but you can see tips for how to do this here:
Trying to connect to an ODBC server using RODBC in ubuntu "
So it seems like it is possible. I'll update if I get it working.
Related
I am trying to connect to a MySQL database through RMySQL but get the following error
"Error in .local(drv, ...) :
Failed to connect to database: Error: Unknown database 'XXX'"
Has anyone had a similar issue and was able to resolve it?
Running
macOS High Sierra, Version 10.13.6
MySQL workbench 8.0
RStudio Version 1.1.453
I constructed the SQL driver as follows:
install.packages("RMySQL")
install.packages("dbConnect")
library(DBI)
library(dbConnect)
con <- dbConnect(RMySQL::MySQL(),
dbname = "xxx",
host = "xxx",
port = xxx,
user = "xxx",
password = "xxx")
I've been following Filip Schouwenaars' datacamp course Importing Data in R (https://www.datacamp.com/courses/importing-data-in-r-part-1) and was hoping to establish a connection to the SQL database and create an MySQLConnection object to then run SQL queries from inside R.
The problem is that I get stuck at the very beginning because of the failure to connect to database. In MySQLworkbench, the script opens and looks great. I'm a complete newbie at this, and am wondering whether this may have something to do with the location of the database file itself? Should I be saving it in a specific folder?
PS: I've read through all RMySQL threads on here and could not find a solution; if I missed something, please let me know. This is my first ask on this forum, and I'm both super grateful for the community here but also worried that I missed something, somewhere. THANK YOU for your help.
Solution: I did in fact not have a 'database' (or schema, as they are now called in MySQL), but merely an .sql file. Once I created a database from the file, it worked like a charm!
For other newbies out there, especially in the humanities, this was a very helpful tutorial on how to set up MySQL with R: https://programminghistorian.org/en/lessons/getting-started-with-mysql-using-r
I'm using Access VBA to call an R script that builds some charts. This R script pulls some data from the Access database via an ODBC query. I'm using library(RODBC) to make the connection from R.
If I restart Access, or run Compact/Repair, the query will always run. However, if I make other changes in the database, I'll sometimes get the following warning:
Warning messages:
1: In odbcDriverConnect(sprintf("Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=%s", :
[RODBC] ERROR: state HY000, code -3810, message [Microsoft][ODBC Microsoft Access Driver] The database has been placed in a state by an unknown user that prevents it from being opened or locked.'
And the script fails to run, because the connection couldn't be made.
What's the best way to manage/set the state of the database so the query will always run? The issue isn't directly linked to whether a table is open or not - I can open a table, and close a table, and not have an issue, and even run with a table open, sometimes.
Edit: The error is caused by making any sort of change in a VBA module (this is unrelated to the actual VBA call of the script, I can run the same rscript call in the command line and replicate the error). Now that I understand that's the cause, I don't think it's a big issue. Saving the VBA module sometimes seems to correct the error, although not 100% of the time.
This is by design.
Making any design change to a VBA module, form or report sets an exclusive lock on an accdb file, which remains until the Access application that has made the change closes.
Just close and re-open the file after making any design change to a form, report or VBA module.
This is one of the reasons people recommend you split the database, since then you can change the design without locking people out of the data.
I have been trying to make a connection between R and the SQL server but I keep getting this error msg:
object 'C_RODBCDriverConnect' not found
It seems as if R is trying to find that object but is failing in doing so, anyone have an idea on how I can solve this issue?
Reinstalling R is not an option as it's a work computer and I do not have the rights to do so. Also note that I am using the RODBC package as the odbc package doesn't want to install properly (I kept getting the zero non-exit error msg).
Thanks in advance.
Zachary
Just make sure you make a odbc connection in the odbc data sources and ensure you have done it correctly to the sql server database.
library(RODBC)
#ODBC_1 refer to Database you want to use
con_ref = odbcConnect("name_of_connection")# name of connection is what you used in odbc connection setup
#input data
x <- sqlQuery(con_ref, "select * from db_name")
I'm trying to establish a connection between R and a Sequel Server Analysis Services (SSAS) Cube. Similar questions have been asked before here and here, but I haven't been able to find an easy answer. HTTP access through the X4R package is discussed here, but the SSAS cube I have access to is not configured for HTTP connections.
Using the RDCOMClient library, I can create an "ADO Connection" object with
con <- COMCreate("ADODB.Connection")
Following the script here, I would like to write something like
con[["ConnectionString"]] <- paste(
"Provider=MSOLAP.4",
"Server=myserver",
"Initial Catalog=mycatalog",
sep = ";")
con$Open()
to specify the connection string and open the connection. The labels myserver and mycatalog are set to their appropriate values based on the connection I am able to establish between Excel and SSAS.
However, my connection string is probably not correctly specified because I get the error
<checkErrorInfo> 80020009
No support for InterfaceSupportsErrorInfo
checkErrorInfo -2147352567
Error: Exception occurred.
I don't know how to debug this error either. Could someone advise
the appropriate COM class to use (i.e. is "ADODB.Connection" correct?)
the key-value pairs required for the "ConnectionString" element of the COM class object
where I can find more information about these topics (the MSDN ADO MD for developers pages are quite difficult for a non-developer)
if there is a better way to go about establishing a connection between R and an SSAS Cube
How is the path to "myserver" defined? I got this error when I confused R and SSAS with backslashes/forward slashes.
I used this post to help with correct syntax and then the error disappeared (i.e. I used backwards slashes and added an extra backslash for each one to escape them)
I've been trying to connect my company's DMS to R using the odbcConnect command, but get the following message:
myConn <-odbcConnect("NZSQL", uid="cejacobson", pwd="password")
Warning messages:
1: In odbcDriverConnect("DSN=NZSQL;UID=cejacobson;PWD=password") :
[RODBC] ERROR: state IM002, code 0, message [unixODBC][Driver Manager]Data source name not found, and no default driver specified
2: In odbcDriverConnect("DSN=NZSQL;UID=cejacobson;PWD=password") :
ODBC connection failed
The thing is, I'm positive the Data source name is NZSQL and my uid and password are correct as well. Any insight as to why R may not be finding my data source / driver (the driver is, by the way, specified and working).
How can I fix this?
I ran across this same problem when I was first trying to connect to an Oracle database. In the end what worked for me was using odbcDriverConnect and a connection string instead of odbcConnect.
myConn <-odbcDriverConnect("Driver={Oracle in OraClient11g_home1};Dbq=NZSQL;Uid=cejacobson;Pwd=password;")
You can check on https://www.connectionstrings.com/ for your specific connection string for your database. Mine happened to be this one.
Hope this helps.
This is IM02 error which means name of the DSN is incorrect.
GO to ODBC and check the USER/System DSN that you should be using. Once your name of DSN is correct, you might get IM014 state error which is archtecture mismatch. In that case,
The simpler solution is
IN r studio - go to tools and change the version of R to 32 bit.
It should be ready to work
I was trying to access SQL Server database and got the same error. After using the correct format of db connection, I got access to my sql server database.
dbhandle <- odbcDriverConnect("Driver={SQL Server};Server=mydbhost;Database=mydbname;Trusted_Connection=Yes")
I know this is old but also make sure that you remove the spaces around the '=' sign. That was my problem.
What worked for me was a 32 bit connection instead of a 64 bit connection.
I just spent days on this. If you are using a Microsoft Access database you have to use the full path to the database, it won't even find the file in the same folder.
So from the above question,
myConn <-odbcConnect("NZSQL", uid="cejacobson", pwd="password")
Would need to be something like
myConn <-odbcConnect("c:\\NZSQL", uid="cejacobson", pwd="password")
Phil's link really helped:
https://www.connectionstrings.com/
I had the same problem, what helped me was to add the driver manually:
Search for ODBC Data Source Administrator and click the 64 bit option
Click on "dBASE Files" and then "Add"
Double click on "Oracle in XE"
Fill Data Source Name (NZSQL in your example) and TNS Service Name fields.
Click on Ok.
After that you may go to RStudio again and you will be able to connect using odbcConnect().
I just used R x64 (64-bit) instead of R i386 (32-bit) and it worked