Using dplyr to connect to SSL-encrypted remote database - r

I would like to use the dplyr package in R but to connect to a remote database that is SSL-encrypted. How do I set up a workaround here? I'm thinking of setting up a backend that uses the RODBC package. Is this possible?

Actually you can connect to a an SSL-encrypted connection with dplyr and it's easy.
You just need to pass the parameters for your connection within the dbname parameter, like this (this is a postgresql example):
db <- src_postgres(dbname="dbname=my_db sslcert=my_cert.crt sslkey=my_key.key sslmode=require", user="username", host="your.host.com")

Related

Connecting to an Azure SQL Server Data Warehouse from R on a Mac - See random names instead of tables

I'm trying to connect to an Azure SQL Server (12.00.1900) from R on a Mac, using Microsoft's unixodbc SQL Server drivers (17).
I get a connection, but instead of seeing the 12 or so tables that live in the database, dbListTables returns 442 tables, all with nonsensical names, beginning with 'Csoe', 'Ote', and ending in 'xlshm_idad'. Instead of seeing the single schema that lives in the database, I see cin_1mro__e, IFRAINSHM, and s, none of which have any tables in them.
Note that when I use an ordinary SQL visualization app, that doesn't use the MS drivers, I'm able to see the tables and their content properly.
In addition, the RSQLServer package gets a working connection and sees the tables correctly, but isn't compatible with dplyr semantics.
Can anyone help or advise? I've looked for third party SQL Server unixodbc drivers for Mac, and I can't find any.
Until I see more info from OP, I'll leave as my answer the general recommendation to use R's odbc package. Assuming the correct drivers are installed, connection is configured correctly in odbc.ini, and assuming trusted_connection=yes is used in the same, then connecting from R is as simple as:
library(odbc)
dbConn <- dbConnect(odbc(), dsn = "myDSN")
if trusted connection is not on then you just need to pass uid and pwd arguments.
Also, it may be the case OP that you did not install freeTDS, so try (replace with equivalent for package manager you're using):
brew install freetds --with-unixodbc
This gives you the libtdsodbc.so driver. Make sure the DSN points to this.

Library to connect Rstudio to MemSQL Database

Is the library needed to connect to a MemSQL database the same as the one used for MySQL?
Would the library(RMySQL) work to establish this connection?
Yes, in general you can connect to MemSQL using the same client libraries as for MySQL. Try it out and ask if you run into any problems.
Nothing directly about Rstudio, but there are many examples of how to connect to MemSQL with various clients at https://docs.memsql.com/tutorials/v6.0/how-to-connect-to-memsql.

Using RPostgreSQL to list the databases

I am looking for an R command to list the available databases in a PostgreSQL server. I am using RPostgreSQL package in R.
I know how to connect to the server but the only thing I need to know is how to list the names of available databases.
Once you're connected to the server you can use this query:
dbGetQuery(con, "SELECT datname FROM pg_database WHERE datistemplate = FALSE")
con is the name of your connection.

Connecting R and Redshift via dplyr

I am willing to use data from R which is stored in Redshift. I have no problems connecting via the redshift package:
library(redshift)
conn_redshift <- redshift.connect("jdbc:postgresql://host:port/dbname",
user,
password)
table_Names <- redshift.tables(conn_redshift)$table_name
This works fine. However, I am a fan of the dplyr interface, but I have problems to connect via src_postgres. Therefor I first tried to create a local database, this is working as well:
library(dplyr)
connection <- src_postgres(dbname, user,password, host = "localhost")
However, when I add the Redshift credentials
myRedshift2 <- src_postgres(dbname, host ,port, user,password)
I get the following error
Error in postgresqlNewConnection(drv, ...) :
RS-DBI driver: (could not connect ... on dbname)
Since I am able to connect to a postgres database locally it seems that it can not be an installation/driver problem and since I can connect to redshift via another package, it seems that it can not be a permission (IP filter) problem. The code that I have written is working on a colleagues laptop as well, so it shouldn't be code problem neither. We have compared sessionInfo(), but that is exactly the same. Does anyone have another possible idea?

RCassandra is not connecting to Cassandra Database

I'm new to Cassandra and R. When I'm connecting to Cassandra database using RCassandra package, connection is establishing. But When trying to use any keyspace, R is not responding. I used the following statements.
c <- RC.connect('192.168.1.20', 9042)
RC.use(c, 'effesensors')
Please give me a brief idea about how to use RCassandra to avoid this problem.
Are you aware that you may be using a non default port for Cassandra? If you can provide the Cassandra version and RStudio version I may be able to update my answer. I found this tutorial by tarkalabs useful as a checklist of steps to take before any connection is attempted.
From the tutorial,
Now connect to your database with connect.handle <-
RC.connect(host="127.0.0.1", port=9160)
Cassandra by default listens to port 9160 but you can change it
according to your configuration. To show the cluster type into your
prompt RC.cluster.name(connect.handle)
Just to verify that you are connected and your Cassandra instance is running try the following command:
RC.describe.keyspaces(connect.handle)
That should bring back a list of the settings in your keyspaces. If nothing returns, you are either not connected or your Cassandra instance is not properly installed.
EXAMPLE OUTPUT
$system_traces$strategy_options
replication_factor
"2"
$system_traces$cf_defs
named list()
$system_traces$durable_writes
[1] TRUE
Let me know what your results are if my answer does not work and I will update my answer. Good Luck!
make use of RODBC instead of using RCassandra. We need to install Cassandra ODBC driver.
Thanks #D. Venkata Naresh, your suggestion of using RODBC driver resolved my issue.
I am using R and datastax cassandra community edition.
This is the link I followed to configure the ODBC driver in my windows machine.
https://www.datastax.com/dev/blog/using-the-datastax-odbc-driver-for-apache-cassandra
Then, in my R studio, These are the commands to connect and fetch from the Cassandra
install.packages("RODBC")
library("RODBC")
require("RODBC")
conn <- odbcConnect(<ODBC datasource name>)
dataframe <- sqlFetch(conn, <column family / table name>)
dataframe
Hope, this answer helps someone who is facing issue with RCassandra.
I read your comments above, you are using the wrong port. You should run the following command
c <- RC.connect('192.168.1.20', 9160)
This will definitely work for you.

Resources