connecting to Oracle DB using Windows authentication / trusted connection in R - r

There are a lot of examples how to connect to an Oracle DB using password authentication (i.e. user id + password) in R. However, I need to figure out to set up the connection using Windows authentication / a trusted connection in R for an Oracle DB.
Example
I saw a similar case for a MySQL DB where a connection string is specified containing trusted_connection=true which, if I understand correctly, indicates Windows authentication / a trusted conenction.
library(RODBC)
dbhandle <- odbcDriverConnect('driver={SQL Server};server=servername\\\\instancename,port;database=testing;trusted_connection=true')
res <- sqlQuery(dbhandle, 'select * from information_schema.tables')
1) How exactly would that look like for Oracle DB using the information below?
Additional info (maybe useful):
In the tsnames.ora config file I added the following database address, which works using MS Access.
DBNAME.XXX.COM =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = DBNAME.XXX.COM)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = DBNAME.XXX.COM)
)
)

Related

R JDBC snowflake connection using ssh key auth

I have a Rstudio setup with no browser and only terminal access to internet.
Having issues following the guides for snowflake connections with Rstudio and dplyr library using ssh keys for auth, can confirm access to the tenant via browser outside of terminal. I also tried the jdbcDriver jar directly and connection to no avail.
Any pointers would be helpful
Examples below, tried with and without region
install.packages(c("rJava"))
install.packages(c("RJDBC", "DBI", "dplyr"))
install.packages("devtools")
devtools::install_github("snowflakedb/dplyr-snowflakedb")
library(RJDBC)
library(dplyr)
library(dplyr.snowflakedb)
options(dplyr.jdbc.classpath = "/opt/snowflake-jdbc-3.9.2.jar")
snowflake_con <- src_snowflakedb(user = "myusername#domain.comm", password = "mypassword", private_key_file = "/home/ssh-keys/rsa_key.p8", private_key_file_pwd="myfilepassword", host = "myhost.eastus2.snowflakecomputing.com", opts = list(warehouse = "WAREHSE", db = "DB", schema = "CB", authenticator="externalbrowser"))
jdbcConnection <- dbConnect(jdbcDriver, "jdbc:snowflake://<account><.region_id>.snowflakecomputing.com", "<username>","<password>")
jdbcConnection <- dbConnect(jdbcDriver, "jdbc:myhost.eastus2.snowflakecomputing.com", private_key_file = "/home/ssh-keys/rsa_key.p8", private_key_file_pwd="myfilepassword")
tried following snowflakes guide here but this just uses username and password which requires the auth verified.
https://community.snowflake.com/s/article/connecting-r-to-snowflake-using-the-jdbc-driver-mac-os-x
https://snowflakecommunity.force.com/s/article/How-TO
You will either need a user configured with password authentication or Key Pair Authentication. SSO authentication will not work for you in the absence of a browser. After creating the keys, you will need to assign the key to the Snowflake user. Finally, here is how to configure JDBC configuration to use key pair authentication

How to create a table in SQL Server with RevoScaleR?

I'd like to create a table in my SQL Server database running on a local instance and populate it with mine predicitve model written in R; to which aim I call these lines of R script:
predictionSql = RxSqlServerData(table = "Logit_FPD60_ZIP", connectionString = connStr)
predict_logit = rxPredict(logit_model, input_data, outData = predictionSql)
...which returns:
[Microsoft][ODBC SQL Server Driver][SQL Server]Login failed for user
'my server'.
I can establish a connection and preview data from the server.
I've tried:
Set SQL Server and Windows Authentication mode in my SQL Server
Security properties and restart both the service and Lunchpad.
Create a generic SQL Server Connector
which is:
[ODBC] DRIVER=SQL Server Native Client 11.0 DATABASE=Predict
WSID=NB-IT-JIRAK APP=Operační systém Microsoft® Windows®
Trusted_Connection=Yes SERVER=NB-IT-JIRAK\SJ Description=Generic SQL
Connector
I'm using this connection string in R:
connStr <- paste("Driver=SQL Server; Server=", "NB-IT-JIRAK\\SJ",
";Database=", "Predict", ";Trusted_Connection=true", sep = "");
What am I missing? New to R, help would be appreciated. Thanks in advance.
Change connection string to sa if it is a test machine or a use a privileged account:
connection_string <- sprintf("Driver=SQL Server;Server=%s;Database=%s;Uid=sa;Pwd=mypass", server, db_name)
commented: --> connection_string <- sprintf("Driver=SQL Server;Server=%s;Database=%s;Trusted_Connection=Yes", server, db_name)

Always Encrypted is not working for Where condition

I am using SQL Server 2016 to use always encryption option. I have 2 servers. I kept SQL Server 2016 in server and encrypted columns for my DB. I have hosted my ASP.NET MVC application on the other server using IIS. I am using Entity Framework to connect with SQL Server. I have added the column encryption setting=enabled; in my connection string.
I have also imported the certificate to the server in which my application hosted in IIS.
While running the below code, I am getting an error.
var userName= context.testtable.Where(p => p.email == "melody#gmail.com").FirstOrDefault();
Error
The data types varchar and varchar(100) encrypted with (encryption_type = 'DETERMINISTIC', encryption_algorithm_name = 'AEAD_AES_256_CBC_HMAC_SHA_256', column_encryption_key_name = 'CEK_Auto1', column_encryption_key_database_name = 'testdb') collation_name = 'Latin1_General_BIN2' are incompatible in the equal to operator.

DB2OLEDB v5 and SQL Server 2016

I connect to an AS400 database using DB2OLEDB v5 as a linked server from SQL Server 2016--but Binary to Character will not translate. All binary fields on the AS400 database are returned as hex on the SQL Server. Has anyone had success using this type of linked server from SQL Server 2016? The provider string below is the same one I used successfully on SQL Server 2012. I really appreciate any help that can be provided. Here is my Provider string:
exec master.dbo.sp_addlinkedserver #server = N'JDE'
, #srvproduct = N'DB2OLEDB'
, #provider = N'DB2OLEDB'
, #datasrc = N'192.168.x.x'
, #provstr = N'Provider=DB2OLEDB;
User ID=########;
Password=########;
Initial Catalog=S06822B5;
Network Transport Library=TCPIP;
Host CCSID=37;
PC Code Page=1252;
Network Address=192.168.x.x;
Network Port=446;
Package Collection=QGPL;
Default Schema=CRDDTA;
Process Binary as Character=True;
Units of Work=RUW;
DBMS Platform=DB2/AS400;
Use Early Metadata=False;
Defer Prepare=False;
DateTime As Char=False;
Rowset Cache Size=0;
Datetime As Date=False;
AutoCommit=True;
Authentication=Server;
Decimal As Numeric=False;
Derive Parameters=True;
LoadBalancing=False;
Persist Security Info=False;
Cache Authentication=False;
Mode=Read;
Connection Pooling=False;'
, #catalog = N'S06822B5'
/* For security reasons the linked server remote logins password is changed with ######## */
and
exec master.dbo.sp_addlinkedsrvlogin #rmtsrvname = N'JDE'
, #useself = N'False'
, #locallogin = null
, #rmtuser = N'connect'
, #rmtpassword = '########'
Suggestion: for correct connection string and SQL server version use DB2OLEDBV6_x64.msi which part of SQL SERVER 2016 SP2 Feature Pack

Failed to authenticate credentials using Mongolite R

I use R and trying to use the very recent "Mongolite". However I cannot connect to MongoDB server.
The manual clearly states the following:
mongo(collection = "test", db = "test", url = "mongodb://localhost")
This is what I have tried without success, where I have a log token and the port of course.
mongodb://heroku:TOKEN#lennon.mongohq.com:PORT
and keep getting the following error:
Error in mongo_collection_new(url, db, collection) :
Failed to authenticate credentials.
It is tried and true that mongolite (v0.7 as of today) supports authenticated connection to a remote 3.2.x MongoDB (as opposed to localhost).
The example below jeroenooms provides himself worked:
library(mongolite)
mongo(collection = "mtcars", url = "mongodb://readwrite:test#ds043942.mongolab.com:43942/jeroen_test")
To explain:
mtcars is the name of the MongoDB "collection" (or "table" if you insist). It could be a name that does not exist yet.
readwrite is the user name of your mongodb
test is the password of the user "readwrite"
ds043942.mongolab.com is the remote host, which could be replaced by ip address, i.e. 23.20.234.21
43942 is the port number. By default in MongoDB, it is 27017
jeroen_test is the name of the database instance in use, which has to exist already
Running the commands above in R will print:
Mongo Message: SCRAM: authenticating "readwrite" (step 1)
Mongo Message: SCRAM: authenticating "readwrite" (step 2)
Mongo Message: SCRAM: authenticating "readwrite" (step 3)
Mongo Message: SCRAM: "readwrite" authenticated
...
I tried to replace it with my own remote host info. It didn't work in the beginning, which turned to be the user role issue rather than mongolite issue. After ensuring a user with correct readWrite roles, I connected to my remote 3.2.x MongoDB via mongolite package.
The following 2 sources were of great help to me in setting up users in MongoDB:
enable-authentication
Manage User and Roles
If you look into the source code of jeroenooms/mongolite you can see that it doesn't support authentication yet:
https://github.com/jeroenooms/mongolite/blob/master/R/mongo.R
mongo_collection_new <- function(uri = "mongodb://localhost", db = "test", collection = "test"){
stopifnot(is.character(uri))
stopifnot(is.character(db))
stopifnot(is.character(collection))
.Call(R_mongo_collection_new, uri, db, collection)
}
just change the order :
mongo( url = "mongodb://localhost",db = "test",collection = "test")
I found that the following command allowed me to connect to mongodb using mongolite and the legacy SCRAM-SHA-1 authentication mode.
library(mongolite)
mongoUrl <- "mongodb://a_username:a_password#localhost:27017/admin" #<-admin here is the mongodb database that stores the authentication info
# specify your collection
colname <- "a_collection"
# specify your database
dbname <- "a_database"
# create connection (con)
con <- mongo(collection = colname, url = mongoUrl, db=dbname)
# count how many records (fyi this is just a test)
con$count('{}')

Resources