Connect R to Filemaker Pro 15 on Mac - r

I'm trying to create a connection between R (3.3.3) Using RStudio (1.0.143) and Filemaker Pro Advanced 15 (15.0.3.305). I'm trying to create the connection using RODBC (1.3-15).
So far I:
Created a toy FM Pro database for testing
User id: Admin
Password: password
Followed these instructions for creating a DSN
Created a DSN for my toy FM Pro database called test_r
Successfully tested the connection to test_r
Unsuccessfully attempted to connect to the DSN in RStudio in the following two ways:
fm_connection <- odbcConnect(dsn="test_r", uid="Admin", pwd="password")
Which returns the following error:
[RODBC] ERROR: state IM002, code 0, message [unixODBC][Driver Manager]Data source name not found, and no default driver specifiedODBC connection failed
AND
constr <- paste("driver={FileMaker ODBC}",
"server=127.0.0.1",
"database=test_r",
"uid=Admin",
"pwd=password",
sep=";")
fm_connection <- odbcDriverConnect(constr)
Which returns the following error:
[RODBC] ERROR: state 01000, code 0, message [unixODBC][Driver Manager]Can't open lib 'FileMaker ODBC' : file not foundODBC connection failed
However, you can see that the driver is there:
Finally, I've unsuccessfully tried using these (and other) references to resolve this issue:
https://cran.r-project.org/web/packages/RODBC/vignettes/RODBC.pdf
https://community.filemaker.com/thread/165849
Nothing seems to work so far. I'm not tied to RODBC, but I do need a solution that works for Mac OS. Any help is appreciated!

Here are some imortant troubleshooting steps for MacOS. I've had the same error in R and therefore I think there's a good chance that this your issue. The setup of ODBC can be rather complicated since several software components with multiple versions are involved. You've already verified that ODBC sharing is on in this particular FileMaker database.
Verify your installation of unixodbc:
ODBC Manager is actually optional. It manages the ini files described below. But after installing unixodbc, you can also edit these ini files in a text editor without ODBC Manager.
To install Homebrew, execute this command.
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Then, install unixodbc. This provides for ODBC connectivity at the system level.
brew update
brew install unixodbc
Verify the driver:
The driver should be installed here:
/Library/ODBC/FileMaker\ ODBC.bundle/Contents/MacOS
That folder will contain these two files:
SetupToolTemplate fmodbc.so
Here's the full driver path:
/Library/ODBC/FileMaker\ ODBC.bundle/Contents/MacOS/fmodbc.so
Verify the config files:
The folder
/Library/ODBC
should contain these files:
FileMaker ODBC.bundle odbc.ini odbcinst.ini
Additionally, the unixodbc should contain only the latest version. If you have an earlier version, delete it. Now, only 2.3.4 is present.
/usr/local/Cellar/unixodbc/2.3.4
also contains
odbc.ini odbcinst.ini
Mirror the odbc.ini and odbcinst.ini files:
As described above, there are two copies of each of these files in two different locations. Make sure that the contents of both are equal. That means both copies of odbcinst.ini will define the drivers. And both copies of odbc.ini will contain the connections. Maybe this isn't 100% necessary, but it's what I needed to do.
Test with isql:
B:etc bobby$ isql -v DSNname admin password
+---------------------------------------+
| Connected! |
| |
| sql-statement |
| help [tablename] |
| quit |
| |
+---------------------------------------+
If you still have any issues after completing these steps, please share additional details so that I can update the answer.

I got this to work using odbc instead of RODBC some new R code:
con <- DBI::dbConnect(odbc::odbc(),
driver = "/Library/ODBC/FileMaker ODBC.bundle/Contents/MacOS/FileMaker ODBC",
server = "127.0.0.1",
database = "/Users/bradcannell/Dropbox/Filemaker Pro/Notes/test_r.fmp12",
uid = "Admin",
pwd = "password")

Related

Add Snowflake ODBC connection in /etc/odbc.ini

I'm attempting to set up an ODBC connection on an EC2 server on our companies network. Have been reading Snowflake documentation here.
Following the documentation, I used yum to download and install the driver by adding a file /etc/yum.repos.d/snowflake-odbc.repo and then populating it with:
[snowflake-odbc]
name=snowflake-odbc
baseurl=https://sfc-repo.snowflakecomputing.com/odbc/linux/2.22.1/
gpgkey=https://sfc-repo.snowflakecomputing.com/odbc/Snowkey-37C7086698CB005C-gpg
I then ran yum install snowflake-odbc
This appears to have added a connection to our existing /etc/odbc.ini file:
[snowflake]
Description=SnowflakeDB
Driver=SnowflakeDSIIDriver
Locale=en-US
SERVER=SF_ACCOUNT.snowflakecomputing.com
PORT=443
SSL=on
ACCOUNT=SF_ACCOUNT
Chancing my luck I tested this connection in it's current format but it doesn't work. Seems I need to locate some more info / name value pairs and I'm unsure where to get them:
Driver= wants a path to a .so file that I thought would have been installed with my steps outlined above. Not sure where to find this file or what path to use?
When I tested the connection the error I received said I was missing a UID.
The section of the documentation on dns entries has additional details of which settings can be added to odbc.ini, including an example
Driver = /usr/jsmith/snowflake_odbc/lib/libSnowflake.so
Description =
server = yz23456.us-east-1.snowflakecomputing.com
role = analyst
database = sales
warehouse = analysis
Does anyone know where can I find out which settings I need to add to get the odbc connection to work?

Can't open lib 'FreeTDS' : file not found and /etc/odbcinst.ini is missing

I want to connect R to Athena in AWS so that I can get a table from the database into R. So I went online and I googled how to do this. I found this website here. That told me that I need to install drivers. I have a mac (which is also new to me) and I found under the section mac on this website that I need to install homebrew which I did. I then followed these next steps in the terminal.
Install UnixODBC, which is required for all databases
brew install unixodbc
Install common DB drivers (optional)
brew install freetds --with-unixodbc
brew install psqlodbc
I dont usually work in the terminal. So Im not too familiar with it. Anyways I thought that did it so I ran the following code.
con <- DBI::dbConnect(
odbc::odbc(),
Driver = "FreeTDS",
S3OutputLocation = " etc..",
AwsRegion = "etc..",
AuthenticationType = "...",
Schema = "...",
UID = rstudioapi::askForPassword("AWS Access Key"),
PWD = rstudioapi::askForPassword("AWS Secret Key")
)
When I ran this code I got the following error:
Error: nanodbc/nanodbc.cpp:983: 00000: [unixODBC][Driver Manager]Can't open lib 'FreeTDS' : file not found
Of course I googled the error and I found some interesting stuff on stack exchange. After playing around in the terminal though I got these responses:
sudo Rscript -e 'odbc::odbcListDrivers()'
[1] name attribute value
<0 Zeilen> (oder row.names mit Länge 0)
Showing zero rows and row.names with a length of 0.
I also ran this
cp /etc/odbcinst.ini ~/.odbcinst.ini && Rscript -e 'odbc::odbcListDrivers()
and I get this
cmdand quote> '
cp: /etc/odbcinst.ini: No such file or directory
I don't understand why this is the case because I completed steps one and two.
This is to extend what #FlipperPA has mentioned earlier. The s3_staging_dir is the AWS S3 bucket where AWS Athena outputs it's results. By default RAthena tries to keep this tidy by removing adhoc queries results. However this can be stopped by using query caching (https://dyfanjones.github.io/RAthena/articles/aws_athena_query_caching.html).
If you want to get the AWS S3 path of a query you can do the following:
library(DBI)
# connect to AWS Athena, credentials are stored in:
# .aws/credentials or environmental variables
con <- dbConnect(RAthena::athena(), s3_staging_dir="s3://athena/output/")
# Start caching queries
RAthena_options(cache_size = 10)
# Execute a query on AWS Athena
res <- dbExecuteQuery(con, "select * from sampledb.elb_logs")
# AWS S3 Location of query
sprintf("%s%s.csv",res#connection#info$s3_staging, res#info$QueryExecutionId)
Linked stackoverflow question: Can you use Athena ODBC/JDBC to return the S3 location of results?

Unable to Connect to Database using Custom Connection String with ODBC.jl

I'm having trouble connecting to a database with the ODBC.jl package. I can't tell if the problem is with my setup (more likely) or the package. The problem is that ODBC.jl can't seem to locate the correct ODBC driver.
> using ODBC
> ODBC.listdrivers()
/path/to/generic/odbc/
But I need to use a different driver than the one picked up from above.
I'm trying to use a custom connection string as follows:
>ODBC.DSN("DRIVER=path/to/driver/i/want;SERVER=myserver;USER=myuser;PASSWORD=mypass;DATABASE=somedb;")
which returns this:
[ODBC] IM002: [unixODBC][Driver Manager]Data source name not found, and no default driver specified
ERROR: ODBC.ODBCError("ODBC.API.SQLDriverConnect(dbc,window_handle,conn_string,out_conn.ptr,BUFLEN,out_buff,driver_prompt) failed; return code: -1 => SQL_ERROR ")
My understanding is that I should be able to specify the driver as done above, but this does not give the desired connection.
I have .odbc.ini and .odbcinist.ini files set-up in my home directory, which I believe are working correctly. I'm on a Suse enterprise distro. When connecting via isql i have no problems.
Any help is appreciated.

Connecting to Vertica database via pyodbc without odbc.ini on RHEL6

I do not have the permission to edit the system-wide odbc.ini file, therefore I am searching for alternative ways to specify connection parameters towards Vertica.
I have unpacked the needed libraries to a certain location, and am attempting to create a connection string from my "custom" config file.
Is it possible to explicitly specify the path to the driver (and any other necessary parameters) when using pyodbc.connect?
Example intention (fails with the error below):
conn = pyodbc.connect("DRIVER=path/to/libverticaodbc.so;...")
Error:
pyodbc.Error: ('IM002', '[IM002] [unixODBC][Driver Manager]Data source name not found, and no default driver specified (0) (SQLDriverConnect)')
Alternatively, is there another option to use odbc.ini files other than the ones at /etc/, e.g. through setting an environment variable?
I recommend to avoid the use of ODBC driver to connect to Vertica .
Vertica release native driver for python , see attach full details and examples :
https://github.com/uber/vertica-python
I hope you will find it us-full
Thanks
You can put a file called .odbc.ini in your home directory which will be for user specific ODBC settings.
http://www.unixodbc.org/odbcinst.html

How can I connect to a sqlite3 db using pyodbc and unixODBC?

I can't figure out how to connect to a sqlite db using pyodbc. I have a DSN set up and can connect to it via isql without problems.
isql -v TEST
works like a charm, However
import pyodbc
pyodbc.connect('DSN=TEST')
Gives the following error message:
pyodbc.Error: ('IM002', '[IM002] [unixODBC][Driver Manager]Data source name not found, and no default driver specified (0) (SQLDriverConnectW)')
I also tried a great amount of permutations of the connection strings in the examples at https://code.google.com/p/pyodbc/wiki/GettingStarted to no avail.
pyodbc.dataSources()
Does list the dsn I'm trying to connect to with the value holding the path to libsqlite3odbc.so
I assume I am missing something obvious, but I can't figure out what...
EDIT: Using unixODBC 2.3.0, python 2.7.1, sqliteodbc 0.88 and pyodbc 2.1.8
EDIT: The reason I want to use pyodbc is for portability to Windows and MS Access
Just to check what is being passed to the driver manager, turn on ODBC tracing, in your odbcinst,ini file add
[ODBC]
Trace = Yes
TraceFile = /tmp/sql.log
Then run the app again and see what is being passed to the SQLConnect or SQLDriverConnect call.

Resources